in reply to Dynamic Popup Menus

I changed your insert position from 1 to 0, and reversed the array to give a sane menu. Also use warnings and use strict to avoid problems.
#!/usr/bin/perl use warnings; use strict; #set up main window display use Tk; my $mw = new MainWindow(-title => 'PopUp'); my @buttons = qw(A B C D E F G); #popup menu set up my $popupmenu = $mw->Menu(-tearoff => 0); foreach my $bt (reverse @buttons){ $popupmenu->insert(0, 'command', -label => $bt, #-command => [sub {print $popupmenu->cget('text') ."\n" +}], -command => [sub {print $bt ."\n"}], ); } $mw->bind("<Button-3>" => sub {$popupmenu->Popup(-popover => "cursor", -popanchor => 'nw'), -command => [sub {print "Popup\n"}]}); MainLoop();

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

Replies are listed 'Best First'.
Re^2: Dynamic Popup Menus
by skywalker (Beadle) on Sep 30, 2008 at 12:58 UTC
    Thanks for that. I knew it would be some thing simple, just not that simple.