Reputation: 2783
I am new to Perl/Tk and just want to know how I can use a drop down menu in a Perl/Tk-based GUI and how to populate it? Can anyone please help me out with this?
Upvotes: 3
Views: 3110
Reputation: 827
Here is a code fragment (source):
use Tk;
use Tk::Optionmenu;
# have some variables
my ($var, $tvar);
# create a drop down menu
my $opt = $mw->Optionmenu(
-options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]],
-command => sub { print "got: ", shift, "\n" },
-variable => \$var,
-textvariable => \$tvar
)->pack(-side => 'left', -anchor => 'n',);
# populate with some values unless done during initialisation
$opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]);
Upvotes: 4
Reputation: 4581
Every Perl/Tk installation has the widget
demonstration program installed. Just run it; you will find some menu demonstrations under the "Menus" section. I recommend the 2nd item here (titled "As above, but using Perl/Tk -menuitems"). All demonstrations have a "See Code" button for displaying the source code.
Upvotes: 4