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) [ $lab1=>$val1], [$lab2=>val2], ... ] # c) combination of a) and b), e.g., # val1, [$lab2=>val2], val3, val4, [...], ...
If the user should be able to change the available option have a look at Tk::BrowseEntry.
use Tk; my $mw = MainWindow->new();
my ($var, $tvar); my $opt = $mw->Optionmenu( -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]], -command => sub { print "got: ", shift, "\n" }, -variable => \$var, -textvariable => \$tvar )->pack;
$opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]);
my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack; $f->Label(-textvariable=>\$tvar)->pack(-side => 'left'); $f->Label(-text => " -> ")->pack(-side => 'left'); $f->Label(-textvariable=>\$var)->pack(-side => 'left');
$mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack;
MainLoop;
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |