wx.MenuBar¶
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
Class Hierarchy¶
Methods Summary¶
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() |
Properties Summary¶
Class API¶
- class wx.MenuBar(Window)¶
Possible constructors:
MenuBar(style=0) -> None
A menu bar is a series of menus accessible from the top of a frame.
Methods¶
- __init__(self, style=0)¶
Construct an empty menu bar.
- Parameters:
style (long) – If
wx.MB_DOCKABLE
the menu bar can be detached (wxGTK only).- Return type:
None
- Append(self, menu, title)¶
Adds the item to the end of the menu bar.
- Parameters:
- Return type:
bool
- Returns:
True
on success,False
if an error occurred.
See also
- Check(self, id, check)¶
Checks or unchecks a menu item.
- Parameters:
id (int) – The menu item identifier.
check (bool) – If
True
, checks the menu item, otherwise the item is unchecked.
- Return type:
None
Note
Only use this when the menu bar has been associated with a frame; otherwise, use the wx.Menu equivalent call.
- Detach(self)¶
- Return type:
None
- Enable(self, id, enable)¶
Enables or disables (greys out) a menu item.
- Parameters:
id (int) – The menu item identifier.
enable (bool) –
True
to enable the item,False
to disable it.
- Return type:
None
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.
- Parameters:
pos (int) – The position of the menu, starting from zero.
enable (bool) –
True
to enable the menu,False
to disable it.
- Return type:
None
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.
- Parameters:
id (int) – Menu item identifier.
- Return type:
Tuple[MenuItem, Menu]
- FindItemById(self, id)¶
FindItemById(id) . MenuItem
Finds the menu item object associated with the given menu item identifier.
- Return type:
- 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.- Parameters:
title (string)
- Return type:
int
- FindMenuItem(self, menuString, itemString)¶
Finds the menu item id for a menu name/menu item string pair.
- Parameters:
menuString (string) – Menu title to find.
itemString (string) – Item to find.
- Return type:
int
- Returns:
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.
- Parameters:
id (int) – The menu item identifier.
- Return type:
str
- Returns:
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.
- Parameters:
id (int) – The menu item identifier.
- Return type:
str
- Returns:
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).
- Parameters:
menuIndex (int)
- Return type:
- GetMenuCount(self)¶
Returns the number of menus in this menubar.
- Return type:
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.
- Parameters:
pos (int) – Position of the menu on the menu bar, starting from zero.
- Return type:
str
- Returns:
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.
- Parameters:
pos (int) – Position of the menu on the menu bar, starting from zero.
- Return type:
str
- Returns:
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 callingAppend
.- Parameters:
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.
- Return type:
bool
- Returns:
True
on success,False
if an error occurred.
See also
- IsAttached(self)¶
- Return type:
bool
- IsChecked(self, id)¶
Determines whether an item is checked.
- Parameters:
id (int) – The menu item identifier.
- Return type:
bool
- Returns:
True
if the item was found and is checked,False
otherwise.
- IsEnabled(self, id)¶
Determines whether an item is enabled.
- Parameters:
id (int) – The menu item identifier.
- Return type:
bool
- Returns:
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.- Parameters:
pos (int) – The menu position (0-based)
- Return type:
bool
Added in version 2.9.4.
- static MacGetCommonMenuBar()¶
Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
- Return type:
- Returns:
The global menubar.
Note
Only exists on Mac, other platforms do not have this method.
Availability
Only available for OSX.
- static 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.
- Parameters:
menubar (wx.MenuBar) – The menubar to set.
- Return type:
None
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.
- Return type:
Added in version 4.0/wxWidgets-3.0.1.
Availability
Only available for OSX.
- Refresh(self, eraseBackground=True, rect=None)¶
Redraw the menu bar.
- Parameters:
eraseBackground (bool)
rect (wx.Rect)
- Return type:
None
- 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.- Parameters:
pos (int)
- Return type:
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.
- Parameters:
id (int) – Menu item identifier.
helpString (string) – Help string to associate with the menu item.
- Return type:
None
See also
- SetLabel(self, id, label)¶
Sets the label of a menu item.
- Parameters:
id (int) – Menu item identifier.
label (string) – Menu item label.
- Return type:
None
Note
Use only after the menubar has been associated with a frame.
See also
- SetMenuLabel(self, pos, label)¶
Sets the label of a top-level menu.
- Parameters:
pos (int) – The position of a menu on the menu bar, starting from zero.
label (string) – The menu label.
- Return type:
None
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.
Properties¶