in reply to Tkx treeview setting focus

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

Replies are listed 'Best First'.
Re^2: Tkx treeview setting focus
by Anonymous Monk on Apr 18, 2016 at 22:03 UTC
    $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();

        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?

      I found the solution....it was
      $tree->selection_set($gLast_id);
      not focus