Menubutton(3pm)
π Tk::Menubutton π
okay bestie, gather round, because this one is the menubutton page β Tk::Menubutton, the Perl/Tk widget that makes menus pop off. no cap, it's iconic. let's get into it π
β¨ NAME β¨
Tk::Menubutton β create and manipulate Menubutton widgets. yes that's it, that's the whole vibe. π
πΈ SYNOPSIS πΈ
$menubutton = $parent->Menubutton(?options?);
look at her. so simple. so powerful. π¦
π STANDARD OPTIONS π
these are the standard ones, the classics, the ones everybody knows:
-activebackground-activeforeground-anchor-background-bitmap-borderwidth-cursor-disabledforeground-font-foreground-highlightbackground-highlightcolor-highlightthickness-image-justify-padx-pady-relief-takefocus-text-textvariable-underline-wraplength
fr fr, if you wanna know what any of these actually do, go read Tk::options β that's where the details live. π
π WIDGET-SPECIFIC OPTIONS π
these are the ones that make a menubutton a menubutton. the main character options, if you will. β¨
-compound- Command-Line Name:
-compound - Database Name:
compound - Database Class:
Compound - tells you whether the button should show both an image and text, and if it does, where the image goes relative to the text. the valid values are
bottom,center,left,none,rightandtop. default isnone, which means the button shows either an image or text, depending on what-imageand-bitmapare set to. πΌοΈ
- Command-Line Name:
-direction- Name:
direction - Class:
Height - Switch:
-direction - says where the menu is gonna pop up.
abovetries to pop the menu above the menubutton.belowtries to pop it below the menubutton.lefttries to pop it to the left of the menubutton.righttries to pop it to the right of the menu button.flushpops the menu directly over the menubutton. β¬οΈβ¬οΈβ¬ οΈβ‘οΈ
- Name:
-height- Name:
height - Class:
Height - Switch:
-height - the desired height of the menubutton. if an image or bitmap is being displayed in the menubutton, the value is in screen units (i.e. any of the forms acceptable to
Tk_GetPixels); for text it's in lines of text. if you don't specify this option, the menubutton's desired height gets computed from the size of the image or bitmap or text being displayed in it. π
- Name:
-indicatoron- Name:
indicatorOn - Class:
IndicatorOn - Switch:
-indicatoron - the value must be a proper boolean value. if it's true, a small indicator rectangle gets displayed on the right side of the menubutton, and the default menu bindings will treat this as an option menubutton. if it's false, no indicator is displayed. no cap. π
- Name:
-menu- Name:
menu - Class:
MenuName - Switch:
-menu - the path name of the menu associated with this menubutton. the menu must be a child of the menubutton. periodt. π
- Name:
-state- Name:
state - Class:
State - Switch:
-state - one of three states for the menubutton:
normal,active, ordisabled. innormalstate the menubutton is displayed using the foreground and background options. theactivestate is typically used when the pointer is over the menubutton, and in that state the menubutton is displayed using the activeForeground and activeBackground options.disabledmeans the menubutton should be insensitive: the default bindings will refuse to activate the widget and will ignore mouse button presses. in that state the disabledForeground and background options determine how the button is displayed. π
- Name:
-width- Name:
width - Class:
Width - Switch:
-width - the desired width of the menubutton. if an image or bitmap is being displayed in the menubutton, the value is in screen units (i.e. any of the forms acceptable to
Tk_GetPixels); for text it's in characters. if you don't specify this option, the menubutton's desired width gets computed from the size of the image or bitmap or text being displayed in it. π
- Name:
π¦ DESCRIPTION π¦
The Menubutton method creates a new window (given by the $widget argument) and makes it into a menubutton widget. you can pass additional options, described above, on the command line or in the option database to configure aspects of the menubutton like its colors, font, text, and initial relief. the menubutton command returns its $widget argument. at the time this command is invoked, there must not already exist a window named $widget, but $widget's parent must exist. β οΈ
a menubutton is a widget that displays a textual string, bitmap, or image and is associated with a menu widget. if text is displayed, it must all be in a single font, but it can occupy multiple lines on the screen (if it contains newlines or if wrapping occurs because of the wrapLength option) and one of the characters may optionally be underlined using the underline option. in normal usage, pressing mouse button 1 over the menubutton causes the associated menu to be posted just underneath the menubutton. if the mouse is moved over the menu before releasing the mouse button, the button release causes the underlying menu entry to be invoked. when the button is released, the menu is unposted. π±οΈβ¨
menubuttons are typically organized into groups called menu bars that allow scanning: if the mouse button is pressed over one menubutton (causing it to post its menu) and the mouse is moved over another menubutton in the same menu bar without releasing the mouse button, then the menu of the first menubutton is unposted and the menu of the new menubutton is posted instead. the way that works is genuinely so satisfying. π
there are several interactions between menubuttons and menus; see the menu manual entry for info on various menu configurations, such as pulldown menus and option menus. π
π WIDGET METHODS π
The Menubutton method creates a widget object. this object supports the configure and cget methods described in Tk::options, which you can use to enquire about and modify the options described above. the menu method returns the menu associated with the widget. the widget also inherits all the methods provided by the generic Tk::Widget class. she's got range. π
π DEFAULT BINDINGS π
Tk automatically creates class bindings for menubuttons that give them the following default behavior:
- A menubutton activates whenever the mouse passes over it and deactivates whenever the mouse leaves it. π
- Pressing mouse button 1 over a menubutton posts the menubutton: its relief changes to raised and its associated menu is posted under the menubutton. if the mouse is dragged down into the menu with the button still down, and if the mouse button is then released over an entry in the menu, the menubutton is unposted and the menu entry is invoked. π±οΈ
- If button 1 is pressed over a menubutton and then released over that menubutton, the menubutton stays posted: you can still move the mouse over the menu and click button 1 on an entry to invoke it. once a menu entry has been invoked, the menubutton unposts itself. π₯
- If button 1 is pressed over a menubutton and then dragged over some other menubutton, the original menubutton unposts itself and the new menubutton posts. β¨
- If button 1 is pressed over a menubutton and released outside any menubutton or menu, the menubutton unposts without invoking any menu entry. πͺ
- When a menubutton is posted, its associated menu claims the input focus to allow keyboard traversal of the menu and its submenus. see the menu documentation for details on these bindings. β¨οΈ
- If the underline option has been specified for a menubutton then keyboard traversal may be used to post the menubutton:
Alt+x, wherexis the underlined character (or its lower-case or upper-case equivalent), may be typed in any window under the menubutton's toplevel to post the menubutton. π - The
F10key may be typed in any window to post the first menubutton under its toplevel window that isn't disabled. πΉ - If a menubutton has the input focus, the
spaceandreturnkeys post the menubutton. β£
if the menubutton's state is disabled then none of the above actions occur: the menubutton is completely non-responsive. π
the behavior of menubuttons can be changed by defining new bindings for individual widgets or by redefining the class bindings. iykyk. π§
π KEYWORDS π
menubutton, widget
and that's the whole page, bestie!! π this one shipped as part of perl v5.40.1, dated 2025-04-13 β so yeah, she's fresh, she's documented, she's serving. go forth and pop some menus. π«ΆπΈβ¨
π¦ 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