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?
Asked
Active
Viewed 2,907 times
3 Answers
4
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.

Slaven Rezic
- 4,571
- 14
- 12
4
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]);

capfan
- 817
- 10
- 26