MenuButton
A themed button that pops up a Menu when clicked — useful for a
toolbar drop-down or an options button.
Attach a menu by building one as a child of the menu button and assigning it to
the menu option.
Live preview
Click it to drop the menu; the Theme switcher in the toolbar restyles it live:
Live preview. In the Player's built-in docs viewer (
scriptweaver --help), this rendersMenuButtonas a live, theme-aware widget you can interact with.
Example
const mb = app.MenuButton({ text: 'View', direction: 'below' });
mb.pack.configure({ padx: 8, pady: 8 });
const menu = mb.Menu({ tearOff: false });
menu.addRadiobutton({ label: 'List' });
menu.addRadiobutton({ label: 'Icons' });
menu.addSeparator();
menu.addCommand({ label: 'Refresh', command: () => console.log('refresh') });
mb.menu = menu; // a Menu serialises to its widget path
See Menu for the full set of entry methods (addCommand,
addCheckbutton, addCascade, …).
Options
| Option | Type | Description |
|---|---|---|
text |
string | The button label. |
menu |
Menu |
The menu to pop up. |
direction |
string | Where the menu appears: 'below', 'above', 'left', 'right', 'flush'. |
image |
Photo |
An icon instead of, or with, the text. |
compound |
string | Text / image placement. |
state |
string | 'normal' or 'disabled'. |
underline |
number | Index of the mnemonic character. |
style |
string | A ttk style name — the default TMenubutton, or Menubar.TMenubutton for a flat menubar item. |
The raw Tk menubutton (via __native_tcl) also takes background / foreground, relief,
indicatorOn, and font.
Flat menubar style
A real Tk menubar attaches only to a toplevel (app.menu). To fake one inside a
window — a row of top-level items (File / Edit / …), each with its own dropdown —
give each MenuButton the Menubar.TMenubutton style: flat, no indicator
arrow, the container background, and a selection-coloured highlight on hover or
while its menu is posted, so a top-level item and its dropdown read as one surface.
const item = bar.MenuButton({ text: 'File', style: 'Menubar.TMenubutton' });
It's theme-aware — the style re-derives on every app.setTheme(), so it tracks
theme changes for free. (It uses the default container background; a menubar on an
explicitly-coloured frame won't blend.)
Methods
| Method | Description |
|---|---|
invoke() |
Pop up the menu programmatically (MenuButton). |
Plus the inherited widget methods — see Widget basics.