pkm
pkm

Reputation: 2783

Drop down menu using Perl/Tk code?

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

Answers (3)

capfan
capfan

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

Slaven Rezic
Slaven Rezic

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

gangabass
gangabass

Reputation: 10666

TkDocs have a nice Menus section (this is not Tk but Tkx code but this should help)

Upvotes: 0

Related Questions