Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 332
pkm Avatar asked Sep 01 '26 18:09

pkm


2 Answers

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.

like image 150
Slaven Rezic Avatar answered Sep 04 '26 13:09

Slaven Rezic


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]);
like image 37
capfan Avatar answered Sep 04 '26 14:09

capfan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!