Tk::Optionmenu - Let the user select one of some predefined options values
use Optionmenu; $opt = $w->Optionmenu( -options => REFERENCE_to_OPTIONLIST, -command => CALLBACK, -variable => SCALAR_REF, ); $opt->addOptions( OPTIONLIST ); # OPTION LIST is # a) $val1, $val2, $val3,... # b) [ $val1=>$lab1], [$lab2=>val2], ... ] # c) combination of a) and b), e.g., # val1, [$lab2=>val2], val3, val4, [...], ...
The Optionmenu widget allows the user chose between a given set of options.
If the user should be able to change the available option have a look at Tk::BrowseEntry.
(Re)sets the list of options presented.
Defines the callback that is invokes when a new option is selected.
Reference to a scalar that contains the current value of the selected option.
Adds OPTION_LIST to the already available options.
use Tk; my $mw = MainWindow->new(); my $var; my $opt = $mw->Optionmenu( -options => [qw(jan feb mar apr)], -command => sub { print "got: ", shift, "\n" }, -variable => \$var, )->pack; $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]); $mw->Label(-textvariable=>\$var, -relief=>'groove')->pack; $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack; MainLoop;
Menubutton, BrowseEntry
To install Tk, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk
CPAN shell
perl -MCPAN -e shell install Tk
For more information on module installation, please visit the detailed CPAN module installation guide.