in reply to Tk Menu question.
First of all, don't use numbered variables. Use an array. Then you can use map to generate the anonymous array elements. (Oh, I renamed a few of your variables / functions to something more self-documenting.)
#!/usr/bin/winperl use warnings; use strict; use Tk; my @menu_items = splice @{[get_menu_items()]}, 0, 3; @menu_items = ('None') unless @menu_items; my $mw = MainWindow->new(); $mw->Label(-text => 'Right-click for menu...')->pack(); my $m = $mw->Menu(-tearoff => 0,font => "{arial} 12 {bold}",-menuitems + => [ map { [Button => $_, -command => sub { replace($_) }] } @menu_items ]); $mw->bind("<Button-3>" => sub { $m->Popup(-popover => "cursor",popanch +or => 'nw') }); $mw->focus(); MainLoop; sub get_menu_items { return qw(); # return qw(Foo Bar Baz); # return qw(Foo Bar Baz Quux Zod Wibble); }
The code to populate @menu_items is a little obfuscated, but not terribly. You could break it up into an if-else. *shrug*
bbfu
Black flowers blossom
Fearless on my breath
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Tk Menu question.
by perl_seeker (Scribe) on Sep 29, 2003 at 08:13 UTC | |
|
Re: Re: Tk Menu question.
by perl_seeker (Scribe) on Oct 06, 2003 at 08:03 UTC | |
by bbfu (Curate) on Oct 07, 2003 at 12:53 UTC | |
by perl_seeker (Scribe) on Oct 08, 2003 at 06:33 UTC | |
by bbfu (Curate) on Oct 09, 2003 at 21:08 UTC | |
by perl_seeker (Scribe) on Oct 10, 2003 at 05:41 UTC |