Menu::Item(3pm)
β¨ Menu::Item β the manual page, but make it cute β¨
okay bestie, welcome to the Menu::Item(3pm) glow-up. it's Perl, it's Tk, it's giving user contributed perl documentation energy, and we're gonna read it together. grab a snack. π
π NAME π
Tk::Menu::Item β the base class for Menu items. yes, the mother of all menu items. the blueprint. the blueprint that ate. π
πΈ SYNOPSIS πΈ
here's the vibe, verbatim, no cap:
require Tk::Menu::Item;
my $but = $menu->Button(...);
$but->configure(...);
my $what = $but->cget();
package Whatever;
require Tk::Menu::Item;
@ISA = qw(Tk::Menu::Item);
sub PreInit
{
my ($class,$menu,$info) = @_;
$info->{'-xxxxx'} = ...
my $y = delete $info->{'-yyyy'};
}
see how she just... exists? iconic. π
π¦ DESCRIPTION π¦
Tk::Menu::Item is literally the base class, and these babies are all derived from her:
Tk::Menu::ButtonTk::Menu::CascadeTk::Menu::RadiobuttonTk::Menu::Checkbutton
and there's also a Tk::Menu::Separator hanging out in the group chat too, don't forget her. π«Ά
Constructors are declared so that stuff like $menu->Button(...) and friends just do what you would expect. no surprises, no plot twists, just menu items behaving. β¨
π the -label pre-processing moment
the -label option gets pre-processed, which lets you slap a ~ in front of a character to derive a -underline value. so like:
$menu->Button(-label => 'Goto ~Home',...)
is equivalent to:
$menu->Button(-label => 'Goto Home', -underline => 6, ...)
same thing bestie, just the tilde did the work for you. the way that little ~ carries the whole operation... ππ
π the Cascade menu item
the Cascade menu item creates a sub-menu, and she accepts these options:
-menuitemsβ a list of items for the sub-menu. within this list (which is also accepted byMenuandMenubutton) the first two elements of each item should be theconstructorname and the label:
-menuitems => [
[Button => '~Quit', -command => [destroy => $mw]],
[Checkbutton => '~Oil', -variable => \$oil],
]
-postcommandβ a callback to be invoked before posting the menu. she calls ahead. so polite. π-tearoffβ specifies whether the sub-menu can be torn-off or not.-menuvarβ a scalar reference that will be set to the newly-created sub-menu. she gets the new baby's address, fr fr.
π« what you actually get back
the returned object is currently a blessed reference to an array of two items:
- the containing
Menu - the
'label'
and the methods configure and cget are mapped onto the underlying entryconfigure and entrycget. so when you poke one, the other one feels it. iykyk. π
π the whole point of the OO interface
the main purpose of the OO interface is to allow derived item classes to be defined which pre-set the options used to create a more basic item. like, you make a fancy little subclass and she already knows what she's about. main character energy, genuinely. β
π BUGS π
okay so, full transparency, no gatekeeping:
this OO interface is very new. πΌ
using the label as the "key" is a problem for separaror items which don't have one. the alternative would be to use an index into the menu, but that is a problem if items are deleted (or inserted other than at the end). so basically: both options are a little cursed. pick your poison. π
there should probably be a PostInit entry point too, or a more widget like defered 'configure'. noted, filed, manifesting it. π§
and that's the whole page, bestie!! π this was documented in perl v5.40.1, dated 2025-04-13, and it's the Menu::Item(3pm) page β so go forth and build menus, and remember: the tilde does the underlining for you, and you never have to count characters yourself. slay. π
β¨π
π¦ 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