in reply to tk menu commands dont work while button pressed

I'm not sure what you are after, and I'm not the best at Tk menus. Maybe a cascade?
#!/usr/bin/perl use warnings; use strict; use Tk; my $top = MainWindow->new; $top->geometry('100x100+100+100'); my $menu = $top->Menu( -type => 'menubar' ); $top->configure( -menu => $menu ); $menu->Cascade( -label => '~Selections', -tearoff => 1, -menuitems => [ [ Button => 'Level 1 choice 1', -command => [ \&printchoice, 'L1-C1' ] ], [ Button => 'Level 1 choice 2', -command => [ \&printchoice, 'L1-C2' ] ], [ Button => 'Level 1 choice 3', -command => [ \&printchoice, 'L1-C3' ] ], '', [ Cascade => 'Cascade 1', -tearoff => 0, -menuitems => [ [ Button => 'Cascade 1 Level 2 choice 1', -command => [ \&printchoice, 'C1-L2-C1' ] ], [ Button => 'Cascade 1 Level 2 choice 2', -command => [ \&printchoice, 'C1-L2-C2' ] ], [ Button => 'Cascade 1 Level 2 choice 3', -command => [ \&printchoice, 'C1-L2-C3' ] ], ] ], [ Cascade => 'Cascade 2', -tearoff => 0, -menuitems => [ [ Button => 'Cascade 2 Level 2 choice 1', -command => [ \&printchoice, 'C2-L2-C1' ] ], [ Button => 'Cascade 2 Level 2 choice 2', -command => [ \&printchoice, 'C2-L2-C2' ] ], [ Cascade => 'Cascade 3', -tearoff => 0, -menuitems => [ [ Button => 'Cascade 3 Level 3 choice 1', -command => [ \&printchoice, 'C3-L3-C1' ] ], [ Button => 'Cascade 3 Level 3 choice 2', -command => [ \&printchoice, 'C3-L3-C2' ] ], [ Button => 'Cascade 3 Level 3 choice 3', -command => [ \&printchoice, 'C3-L3-C3' ] ], [ Cascade => 'Cascade 4', -tearoff => 0, -menuitems => [ [ Button => 'Cascade 4 Level 4 choic +e 1', -command => [ \&printchoice, 'C4-L +4-C1' ] ], [ Button => 'Cascade 4 Level 4 choic +e 2', -command => [ \&printchoice, 'C4-L +4-C2' ] ], [ Button => 'Cascade 4 Level 4 choic +e 3', -command => [ \&printchoice, 'C4-L +4-C3' ] ], ] ] ] ], ] ], ] ); MainLoop; sub printchoice { my $choice = shift; print $choice, "\n"; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: tk menu commands dont work while button pressed
by mpage (Initiate) on Jan 23, 2009 at 21:22 UTC
    I dont have any preference whether the new menu is a normal or cascade or whatever...I do need it to appear where the mouse is clicked, however...In my real application I'm binding the right click to a button somewhere in that frame...when pointing at the button the right click brings up a context-sensitive menu ...so I bind it to *that* button to bring up its special menu...if somehow I can have it bring up a cascade that's fine too...but when I modify to have the menu include a cascade like :

    $menu->add('separator'); $menu->add('command', -label => 'One', -command => \&item1); $menu->add('command', -label => 'Two', -command => \&item2); $menu->add('cascade', -label => 'Selections', );

    it has the cascade item labeled "Selections" but holding down the button and dragging over it doesnt do what your cascade example does....can you modify yours somehow to have it create the cascade at the mouse x,y while holding down the mouse click and disappearing when release... matt