A menu bar is a series of menus accessible from the top of a frame.
If you have a toolbar which uses the same identifiers as your EVT_MENU
entries, events from the toolbar will also be processed by your EVT_MENU
event handlers.
Tip: under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu) are not working, check any EVT_CHAR
events you are handling in child windows. If you are not calling event.Skip() for events that you don’t process in these event handlers, menu shortcuts may cease to work.
Note
To respond to a menu selection, provide a handler for EVT_MENU
, in the frame that contains the menu bar.
See also
wx.Menu, Events and Event Handling
Construct an empty menu bar. |
|
Adds the item to the end of the menu bar. |
|
Checks or unchecks a menu item. |
|
Enables or disables (greys out) a menu item. |
|
Enables or disables a whole menu. |
|
Finds the menu item object associated with the given menu item identifier. |
|
FindItemById(id) . MenuItem |
|
Returns the index of the menu with the given title or |
|
Finds the menu item id for a menu name/menu item string pair. |
|
Gets the help string associated with the menu item identifier. |
|
Gets the label associated with a menu item. |
|
Returns the menu at menuIndex (zero-based). |
|
Returns the number of menus in this menubar. |
|
Returns the label of a top-level menu. |
|
Returns the label of a top-level menu. |
|
GetMenus() . (menu, label) |
|
Inserts the menu at the given position into the menu bar. |
|
Determines whether an item is checked. |
|
Determines whether an item is enabled. |
|
Returns |
|
Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open. |
|
Enables you to set the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open. |
|
Returns the Apple menu. |
|
Redraw the menu bar. |
|
Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it. |
|
Replaces the menu at the given position with another one. |
|
Sets the help string associated with a menu item. |
|
Sets the label of a menu item. |
|
Sets the label of a top-level menu. |
|
SetMenus() |
wx.
MenuBar
(Window)¶Possible constructors:
MenuBar(style=0)
A menu bar is a series of menus accessible from the top of a frame.
__init__
(self, style=0)¶Construct an empty menu bar.
style (long) – If wx.MB_DOCKABLE
the menu bar can be detached (wxGTK only).
Append
(self, menu, title)¶Adds the item to the end of the menu bar.
bool
True
on success, False
if an error occurred.
See also
Check
(self, id, check)¶Checks or unchecks a menu item.
id (int) – The menu item identifier.
check (bool) – If True
, checks the menu item, otherwise the item is unchecked.
Note
Only use this when the menu bar has been associated with a frame; otherwise, use the wx.Menu equivalent call.
Detach
(self)¶Enable
(self, id, enable)¶Enables or disables (greys out) a menu item.
id (int) – The menu item identifier.
enable (bool) – True
to enable the item, False
to disable it.
Note
Only use this when the menu bar has been associated with a frame; otherwise, use the wx.Menu equivalent call.
EnableTop
(self, pos, enable)¶Enables or disables a whole menu.
pos (int) – The position of the menu, starting from zero.
enable (bool) – True
to enable the menu, False
to disable it.
Note
Only use this when the menu bar has been associated with a frame.
FindItem
(self, id)¶Finds the menu item object associated with the given menu item identifier.
id (int) – Menu item identifier.
tuple
FindItemById
(self, id)¶FindItemById(id) . MenuItem
Finds the menu item object associated with the given menu item identifier.
FindMenu
(self, title)¶Returns the index of the menu with the given title or NOT_FOUND
if no such menu exists in this menubar.
The title parameter may specify either the menu title (with accelerator characters, i.e. "&File"
) or just the menu label ( "File"
) indifferently.
title (string) –
int
FindMenuItem
(self, menuString, itemString)¶Finds the menu item id for a menu name/menu item string pair.
menuString (string) – Menu title to find.
itemString (string) – Item to find.
int
The menu item identifier, or wx.NOT_FOUND
if none was found.
Note
Any special menu codes are stripped out of source and target strings before matching.
GetHelpString
(self, id)¶Gets the help string associated with the menu item identifier.
id (int) – The menu item identifier.
string
The help string, or the empty string if there was no help string or the menu item was not found.
See also
GetLabel
(self, id)¶Gets the label associated with a menu item.
id (int) – The menu item identifier.
string
The menu item label, or the empty string if the item was not found.
Note
Use only after the menubar has been associated with a frame.
GetMenu
(self, menuIndex)¶Returns the menu at menuIndex (zero-based).
menuIndex (int) –
GetMenuCount
(self)¶Returns the number of menus in this menubar.
int
GetMenuLabel
(self, pos)¶Returns the label of a top-level menu.
Note that the returned string includes the accelerator characters that have been specified in the menu title string during its construction.
pos (int) – Position of the menu on the menu bar, starting from zero.
string
The menu label, or the empty string if the menu was not found.
Note
Use only after the menubar has been associated with a frame.
See also
GetMenuLabelText
(self, pos)¶Returns the label of a top-level menu.
Note that the returned string does not include any accelerator characters that may have been specified in the menu title string during its construction.
pos (int) – Position of the menu on the menu bar, starting from zero.
string
The menu label, or the empty string if the menu was not found.
Note
Use only after the menubar has been associated with a frame.
See also
GetMenus
(self)¶Return a list of (menu, label) items for the menus in the MenuBar
.
Insert
(self, pos, menu, title)¶Inserts the menu at the given position into the menu bar.
Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount
is the same as calling Append
.
pos (int) – The position of the new menu in the menu bar
menu (wx.Menu) – The menu to add. wx.MenuBar owns the menu and will free it.
title (string) – The title of the menu.
bool
True
on success, False
if an error occurred.
See also
IsAttached
(self)¶bool
IsChecked
(self, id)¶Determines whether an item is checked.
id (int) – The menu item identifier.
bool
True
if the item was found and is checked, False
otherwise.
IsEnabled
(self, id)¶Determines whether an item is enabled.
id (int) – The menu item identifier.
bool
True
if the item was found and is enabled, False
otherwise.
IsEnabledTop
(self, pos)¶Returns True
if the menu with the given index is enabled.
pos (int) – The menu position (0-based)
bool
New in version 2.9.4.
MacGetCommonMenuBar
()¶Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
The global menubar.
Note
Only exists on Mac, other platforms do not have this method.
Availability
Only available for OSX.
MacSetCommonMenuBar
(menubar)¶Enables you to set the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
menubar (wx.MenuBar) – The menubar to set.
Note
Only exists on Mac, other platforms do not have this method.
Availability
Only available for OSX.
OSXGetAppleMenu
(self)¶Returns the Apple menu.
This is the leftmost menu with application’s name as its title. You shouldn’t remove any items from it, but it is safe to insert extra menu items or submenus into it.
New in version 4.0/wxWidgets-3.0.1.
Availability
Only available for OSX.
Refresh
(self, eraseBackground=True, rect=None)¶Redraw the menu bar.
eraseBackground (bool) –
rect (wx.Rect) –
Remove
(self, pos)¶Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.
This function may be used together with Insert
to change the menubar dynamically.
pos (int) –
See also
Replace
(self, pos, menu, title)¶Replaces the menu at the given position with another one.
SetHelpString
(self, id, helpString)¶Sets the help string associated with a menu item.
id (int) – Menu item identifier.
helpString (string) – Help string to associate with the menu item.
See also
SetLabel
(self, id, label)¶Sets the label of a menu item.
id (int) – Menu item identifier.
label (string) – Menu item label.
SetMenuLabel
(self, pos, label)¶Sets the label of a top-level menu.
pos (int) – The position of a menu on the menu bar, starting from zero.
label (string) – The menu label.
Note
Use only after the menubar has been associated with a frame.
SetMenus
(self, items)¶SetMenus()
Clear and add new menus to the MenuBar
from a list of (menu, label) items.