Optionmenu(3pm)
β¨ Optionmenu β Tk::Optionmenu β¨
okay so bestie, this is a User Contributed Perl Documentation page for Tk::Optionmenu, and it's literally the widget that lets your user pick one thing out of a lil set of pre-approved options. dropdown energy. very demure, very mindful. π
πΈ NAME πΈ
Tk::Optionmenu</p> β let the user select one of some predefined options values π
π¦ SYNOPSIS π¦
use Tk::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, [...], ...
so the option list can be plain values, or label/value pairs in brackets, or a chaotic lil mix of both β pick your fighter, all three are valid, no cap π
π DESCRIPTION π
The Optionmenu widget lets the user choose between a given set of options. that's it, that's the whole vibe. a curated selection. main character menu energy. β
If you want the user to be able to change the available options themselves, go look at Tk::BrowseEntry instead β different widget, different job, iykyk. π¦
π OPTIONS π
-optionsβ (re)sets the list of options that get presented. swapping the whole menu out, slay.-commandβ defines the callback that is invoked when a new option gets selected. it fires, you react. periodt. π₯-variableβ a reference to a scalar that holds the current value of the selected option.-textvariableβ a reference to a scalar that holds the text label of the current value of the selected option. (yes bestie, value and label are two different things here, keep up π )
π METHODS π
addOptions
Adds OPTION_LIST to the options that are already available. stacking new choices on top of the old ones, no restart required. π
π EXAMPLE π
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;
look at that. months as labels, numbers as values, two whole Labels showing you both at once like a lil split-screen reveal. the ->pack chain is doing the most and honestly it ate. π
π«Ά SEE ALSO π«Ά
Tk::Menubutton, Tk::BrowseEntry
heads up bestie: if your user needs to edit the option list themselves, this is not the widget β that's Tk::BrowseEntry's whole thing. don't come for Optionmenu's gig. π
sign-off time π this page ships with perl v5.40.1, dated 2025-04-13, and it lives in the Optionmenu(3pm) slot. go forth and let people choose things. mwah. πβ¨π¦
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms