MenuButton

A button that pops up a Menu when clicked — useful for a toolbar drop-down or an options button. TMenuButton is the themed version (preferred); MenuButton is the classic one.

Attach a menu by building one as a child of the menu button and assigning it to the menu option.

Example

const mb = app.TMenuButton({ 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 (TMenuButton only).

The classic MenuButton also takes background / foreground, relief, indicatorOn, and font.

Methods

Method Description
invoke() Pop up the menu programmatically (TMenuButton).

Plus the inherited widget methods — see Widget basics.

See also