in reply to Re: Tkx treeview setting focus
in thread Tkx treeview setting focus

$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.

Replies are listed 'Best First'.
Re^3: Tkx treeview setting focus
by previous (Sexton) on Apr 19, 2016 at 06:23 UTC
    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();

      Your program works for me, if the tree control has focus, and I hit insert, then the newly added item has focus,  $tree->focus($gLast_id) worked

      You can give the widget focus with  $tree->g_focus;

      Does that help?

Re^3: Tkx treeview setting focus
by previous (Sexton) on Apr 19, 2016 at 06:44 UTC
    I found the solution....it was
    $tree->selection_set($gLast_id);
    not focus