http://www.perlmonks.org?node_id=349130


in reply to Tk::Tree double click on +

You can override the default double-click binding with your own routine that checks to see if the item double-clicked on is the indicator and, if so, mutates the event into an open/close. Alternatively, you could just have it ignore double-click events on the indicator.

Note, however, that to do so you must replace the binding for the entire class Tk:Tree, so it will affect every Tree widget (and possibly every widget derived from a Tk::Tree) in that window. (You can't bind to the particular Tree instance, because then both callbacks are called, and yours is called last so you can't even use Tk->break to stop propagation, since it's already happened.)

#!/usr/bin/winperl use warnings; use strict; use Tk; use Tk::Tree; my $mw = MainWindow->new(); my $tr = $mw->Tree( -command => sub { print "Tree::command\n" }, )->pack(); $tr->add($_, -text => $_) for qw(Foo Bar Quux); $tr->addchild('Foo', -text => 'Zod'); $tr->autosetmode(); # Replace normal double-click handler with our special routine { my $old = $mw->bind('Tk::Tree', '<Double-ButtonPress-1>'); $mw->bind('Tk::Tree', '<Double-ButtonPress-1>', [ \&invoke, Ev('x'), Ev('y'), $old, ]); } MainLoop; sub invoke { my ($tree, $x, $y, $old) = @_; # Get info about what item was clicked on my ($entry, $subitem) = $tree->info('item', $x, $y); if(defined($subitem) and $subitem eq 'indicator') { #return; # ignore, if you want # Indicator, so just open/close the entry $tree->IndicatorCmd($entry, '<Activate>'); } else { # Not indicator, so propagate #$tree->Double1(); # Don't do this $old->Call($tree); # Instead, use old callback } }

Update: Changed the manual call to Tk::HList::Double1 to use the callback instead, to avoid breaking encapsulation and to be more forward-compatible.

bbfu
Black flowers blossom
Fearless on my breath