Menu#
Menu is tkinter’s menu widget (tk.Menu), themed by ttkbootstrap and
re-exported as ttk.Menu. It backs menu bars, cascading submenus, and
right-click context menus; ttkbootstrap adds helpers for the native macOS
application menu. Entries are addressed by integer index (0-based) or the special
index "end" / "active" / "last". This page is the complete reference
for its own options and methods; the shared widget methods are under
Capabilities.
Options#
Option |
Type |
Description |
|---|---|---|
|
|
Constructor only. |
|
|
The font for entry labels. |
|
|
The text color of entries. |
|
|
The menu background color. |
|
|
The text color of the entry under the pointer. |
|
|
The background color of the entry under the pointer. |
|
|
The border width of the entry under the pointer, in pixels. |
|
|
The text color of disabled entries. |
|
|
The indicator color of checkbutton / radiobutton entries. |
|
|
The 3-D border width in pixels. |
|
|
The border style: |
|
|
|
|
|
A callback invoked when the menu is torn off. |
|
|
A callback invoked just before the menu is posted — use it to update entries lazily. |
|
|
The title shown on a torn-off menu. |
|
|
The menu flavor: |
|
|
The mouse cursor over the menu (see Cursors). |
|
|
Whether the menu accepts keyboard focus during traversal. |
Methods#
Adding entries#
Every add_* appends an entry; the parallel insert_* methods take a
leading index and insert before it.
- add_command(**options)
Append a command entry.
- Parameters:
options –
label,command,accelerator(shown shortcut text),underline,state,image,compound.- Returns:
None.
- add_cascade(**options)
Append a submenu entry.
- Parameters:
options –
labelandmenu(a childMenu), plusunderline,state.- Returns:
None.
- add_checkbutton(**options)
Append a checkbutton entry that toggles a variable.
- Parameters:
options –
label,variable,onvalue,offvalue,command.- Returns:
None.
- add_radiobutton(**options)
Append a radiobutton entry — one choice in a group sharing a
variable.- Parameters:
options –
label,variable,value,command.- Returns:
None.
- add_separator(**options)
Append a horizontal separator line.
- Returns:
None.
- insert(index, itemType, **options)
Insert an entry of
itemType("command","cascade","checkbutton","radiobutton","separator") beforeindex. Theinsert_command/insert_cascade/insert_checkbutton/insert_radiobutton/insert_separatorshortcuts wrap this, andadd(itemType, **options)is the appending equivalent that theadd_*shortcuts wrap.- Returns:
None.
Configuring and removing entries#
- entryconfigure(index, **options)
Set (or query) options on an existing entry. Alias:
entryconfig.- Parameters:
index – the entry to change.
options – any options valid for that entry type.
- Returns:
the option spec when queried with a single option name, else
None.
- entrycget(index, option)
Return one option of an entry.
- delete(index1, index2=None)
Delete an entry, or a range of entries.
- Returns:
None.
- index(index)
Resolve an index expression to an integer entry number.
- Return type:
- type(index)
Return the type of an entry —
"command","cascade","checkbutton","radiobutton","separator", or"tearoff".- Return type:
Posting and invoking#
- tk_popup(x, y, entry='')
Pop the menu up as a context menu at a screen position — the usual way to show a right-click menu.
- post(x, y)
Map the menu at a screen position (lower-level than
tk_popup).- Returns:
None.
- unpost()
Unmap the menu.
- Returns:
None.
- invoke(index)
Invoke the action of an entry as if the user chose it.
- Returns:
the value returned by the entry’s command, if any.
- activate(index)
Highlight an entry as the active one.
- Returns:
None.
- xposition(index)
Return the x pixel coordinate of an entry within the menu;
yposition(index)is the vertical counterpart.- Return type:
macOS application menu (ttkbootstrap)#
These ttkbootstrap additions wire a menu bar into the native macOS menu conventions. Each is a no-op off macOS, so the same code runs everywhere.
- add_application_menu()
Add and return the macOS application menu — the bold, app-named menu that owns About, Preferences…, and Quit.
- Returns:
the application menu, or
Noneoff macOS.- Return type:
Menu | None
- add_window_menu(label='Window')
Add and return the macOS standard Window menu.
- Returns:
the Window menu, or
Noneoff macOS.- Return type:
Menu | None
- add_help_menu(label='Help', command=None)
Add and return a Help menu, wired into the macOS Help conventions.
- Parameters:
command – a callback for the search/help action.
- Returns:
the Help menu, or
Noneoff macOS.- Return type:
Menu | None
- on_preferences(callback)
Enable the macOS Preferences… item (
⌘,) and callcallbackwhen it is chosen. Requiresadd_application_menu().- Returns:
None.
- on_quit(callback)
Call
callbackwhen the user chooses macOS Quit (⌘Q). Requiresadd_application_menu().- Returns:
None.
Shared capabilities#
Menu also has the methods every widget inherits — configuration, event
binding, lifecycle, and introspection. These are documented under
Capabilities.
See also#
Menus — the usage guide.
Tk menu manual page — the canonical upstream reference (Tcl 8.6).