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


In reply to Re: Tk::Tree double click on + by bbfu
in thread Tk::Tree double click on + by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.