previous has asked for the wisdom of the Perl Monks concerning the following question:

How do you programmatically set focus on a node

Replies are listed 'Best First'.
Re: Tkx treeview setting focus
by previous (Sexton) on Apr 18, 2016 at 20:17 UTC
    i.e. I'm creating them like this...
    $gLast_id=$tree->insert($gLast_id, "end", -text => "some_text" ); $tree->item($gLast_id, -open => "true"); #$tree->focus($gLast_id);
    but that focus command isn't doing it
      $gLast_id=$tree->insert($gLast_id, "end", -text => "some_text" ); $tree->item($gLast_id, -open => "true"); #$tree->focus($gLast_id); __END__ Can't call method "insert" on an undefined value at - line 1.
        Sorry you had trouble...try this complete mini-program
        use Tkx; my $mw = Tkx::widget->new("."); #std line $frm_main= $mw->new_frame(); #parent widg probably a frame outsi +de of this compound control $frm_main->g_pack( -expand => 0, -fill => 'x', -side => top); my $tree=$frm_main->new_ttk__treeview; #http://www.tkdocs.com/tut +orial/tree.html $tree->g_pack( -expand => 0, -fill => 'x', -side => top); $gLast_id="root"; $gLast_id=$tree->insert("", "end", -id => $gLast_id, -text => "roo +t"); $tree->item($gLast_id, -open => "true"); #$tree->focus($gLast_id); $tree->g_bind( "<Insert>", sub { $gLast_id=$tree->insert($gLast_id, "end", -text => "some_text +" ); $tree->item($gLast_id, -open => "true"); #http://www.tkdocs.co +m/tutorial/tree.html #$tree->focus($gLast_id); }); Tkx::MainLoop();
        I found the solution....it was
        $tree->selection_set($gLast_id);
        not focus