Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

tree in perl Tkx

by pdbzro (Initiate)
on Jan 31, 2016 at 09:58 UTC ( [id://1154119]=perlquestion: print w/replies, xml ) Need Help??

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

I am using a treeview with perl tkx and i have 4 issues i cannot solve : once populated, the tree display is fine, but :
1- when i clic on a label the procedure clic is called but focus (or selection) gave back the label that have focus before clic but not the clicked one (that is to say it gaves the previously clicked on) so it is necessary to clic again to get the good value
2- when i clic on a node + to open it, the procedure clic is called i expected it was called only when clicking on the label, not on the + sign
3- the two defined scrollbars are visible vertical one works fine when necessary but horizontal one never become active, even when necessary (resize the window to see)
4- there is a blank line at top of the tree display
here is the script
use Tkx; use strict; my $tree; my $mw= Tkx::widget->new("."); $mw->g_wm_focus(); display_tree(); Tkx::MainLoop; sub treeclic { #my $clic=$tree->selection(); my $clic=$tree->focus(); print "$clic\n"; } sub display_tree { $tree=""; $tree=$mw->new_ttk__treeview(); my $scrollbarv=$mw->new_ttk__scrollbar(-orient=>"vertical", -command=> +[$tree,"yview"]); $scrollbarv->g_pack(-side=>'right',-fill=>'y'); my $scrollbarh=$mw->new_ttk__scrollbar(-orient=>"horizontal", -command +=>[$tree,"xview"]); $scrollbarh->g_pack(-side=>'bottom',-fill=>'x'); $tree->configure(-xscrollcommand=>[$scrollbarh,"set"]); $tree->configure(-yscrollcommand=>[$scrollbarv,"set"]); $tree->g_pack(-side=>'top',-anchor=>'w',-expand=>1,-fill=>'both'); $tree->tag_configure("ttk",-background=>"lightblue"); $tree->tag_bind("ttk","<1>",sub{treeclic}); $tree->insert("","end",-id=>"perea",-text=>"perea",-tags=>"ttk simple" +); $tree->insert("perea","end",-id=>"fils",-text=>"fils aaaaaaaaaaaaaaaaa +aaaaaaaaa",-tags=>"ttk simple"); $tree->insert("perea","end",-id=>"fille",-text=>"fille",-tags=>"ttk si +mple"); $tree->insert("","end",-id=>"pereb",-text=>"pereb",-tags=>"ttk simple" +); }

Replies are listed 'Best First'.
Re: tree in perl Tkx
by Anonymous Monk on Jan 31, 2016 at 10:32 UTC

    Initial knee jerk thoughts :D

    1- when i clic on a label the procedure clic is called but focus (or selection) gave back the label that have focus before clic but not the clicked one (that is to say it gaves the previously clicked on) so it is necessary to clic again to get the good value

    Yeah, "focus" is the dark blue color, and I see it changes like its supposed to on first click

    Anyway, <1> is not the event you want, there are other ways to select a node, see the docs http://tcl.tk/man/tcl/TkCmd/ttk_treeview.htm

    Similarly "->focus()" isn't what you want

    2- when i clic on a node + to open it, the procedure clic is called i expected it was called only when clicking on the label, not on the + sign

    When I click on + a newline gets printed on my shell, which means clic must have been called, because its doing the printing

    3- the two defined scrollbars are visible vertical one works fine when necessary but horizontal one never become active, even when necessary (resize the window to see)

    And what tells the scrollbar it should change? Something in Tcl land somwhere ... good luck with that :D

    4- there is a blank line at top of the tree display here is the script

    blank line? I see a "column" "heading" button, not a line, its grey, its documented

      thanks for answering.
      point 2 and 3 : i do not got the solution horizontal scrollbar should allow to show the trailing "aaaaa" for "fils"and it does not
      is it possible to clic on "+" so that node open but procedure clic is not called ?

        i do not got the solution horizontal scrollbar should allow to show the trailing "aaaaa" for "fils"and it does not

        I understand your question, and thats a bug in whatever Tcl/Tk code is responsible for that

        Sure you might be able to workaround or fix it yourself .... like I said, good luck with that :D

        is it possible to clic on "+" so that node open but procedure clic is not called ?

        Sure, why not, but you will have to play with the options, the bindings, and figure stuff out :)

        It this were Tk.pm, you could just use Tk::WidgetDump to view bindings and figure stuff out

        or view the sources to figure that stuff out,

        but since this is Tkx, you would have to hunt down the Tcl sources to figure it out

        The docs mention selectMode ... like I said, good luck :D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1154119]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found