Phoenix Logo

phoenix_title 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.


class_hierarchy Class Hierarchy

Inheritance diagram for class MenuBar:

method_summary Methods Summary

__init__ Construct an empty menu bar.
Append Adds the item to the end of the menu bar.
Attach  
Check Checks or unchecks a menu item.
Detach  
Enable Enables or disables (greys out) a menu item.
EnableTop Enables or disables a whole menu.
FindItem Finds the menu item object associated with the given menu item identifier.
FindItemById FindItemById(id) . MenuItem
FindMenu Returns the index of the menu with the given title or NOT_FOUND if no such menu exists in this menubar.
FindMenuItem Finds the menu item id for a menu name/menu item string pair.
GetFrame  
GetHelpString Gets the help string associated with the menu item identifier.
GetLabel Gets the label associated with a menu item.
GetLabelTop Returns the label of a top-level menu.
GetMenu Returns the menu at menuIndex (zero-based).
GetMenuCount Returns the number of menus in this menubar.
GetMenuLabel Returns the label of a top-level menu.
GetMenuLabelText Returns the label of a top-level menu.
GetMenus GetMenus() . (menu, label)
Insert Inserts the menu at the given position into the menu bar.
IsAttached  
IsChecked Determines whether an item is checked.
IsEnabled Determines whether an item is enabled.
IsEnabledTop Returns True if the menu with the given index is enabled.
MacGetCommonMenuBar Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
MacSetCommonMenuBar Enables you to set the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
OSXGetAppleMenu Returns the Apple menu.
Refresh Redraw the menu bar.
Remove Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.
Replace Replaces the menu at the given position with another one.
SetHelpString Sets the help string associated with a menu item.
SetLabel Sets the label of a menu item.
SetLabelTop Sets the label of a top-level menu.
SetMenuLabel Sets the label of a top-level menu.
SetMenus SetMenus()

property_summary Properties Summary

Menus See GetMenus and SetMenus

api Class API



class wx.MenuBar(Window)

Possible constructors:

MenuBar(style=0)

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).


Append(self, menu, title)

Adds the item to the end of the menu bar.

Parameters:
  • menu (wx.Menu) – The menu to add. Do not deallocate this menu after calling Append .
  • title (string) – The title of the menu, must be non-empty.
Return type:

bool

Returns:

True on success, False if an error occurred.

See also

Insert



Attach(self, frame)
Parameters:frame (wx.Frame) –


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.

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.

Parameters:
  • 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.

Parameters:
  • 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.

Parameters:id (int) – Menu item identifier.
Return type:tuple


FindItemById(self, id)

FindItemById(id) . MenuItem

Finds the menu item object associated with the given menu item identifier.

Return type: wx.MenuItem


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.



GetFrame(self)
Return type: wx.Frame


GetHelpString(self, id)

Gets the help string associated with the menu item identifier.

Parameters:id (int) – The menu item identifier.
Return type:string
Returns:The help string, or the empty string if there was no help string or the menu item was not found.

See also

SetHelpString



GetLabel(self, id)

Gets the label associated with a menu item.

Parameters:id (int) – The menu item identifier.
Return type:string
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.



GetLabelTop(self, pos)

Returns the label of a top-level menu.

Note that the returned string does not include the accelerator characters which could 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:string
Returns:The menu label, or the empty string if the menu was not found.

Deprecated since version 4.0.1: This function is deprecated in favour of GetMenuLabel and GetMenuLabelText .

Note

Use only after the menubar has been associated with a frame.

See also

SetLabelTop



GetMenu(self, menuIndex)

Returns the menu at menuIndex (zero-based).

Parameters:menuIndex (int) –
Return type: wx.Menu


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:string
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.



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:string
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.



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 .

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

Append



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

New 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: wx.MenuBar
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.

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: wx.Menu

New in version 3.0.1.

Availability

Only available for OSX.



Refresh(self, eraseBackground=True, rect=None)

Redraw the menu bar.

Parameters:
  • 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.

Parameters:pos (int) –
Return type: wx.Menu

See also

Replace



Replace(self, pos, menu, title)

Replaces the menu at the given position with another one.

Parameters:
  • pos (int) – The position of the new menu in the menu bar
  • menu (wx.Menu) – The menu to add.
  • title (string) – The title of the menu.
Return type:

wx.Menu

Returns:

The menu which was previously at position pos. The caller is responsible for deleting it.

See also

Insert , Remove



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.

See also

GetHelpString



SetLabel(self, id, label)

Sets the label of a menu item.

Parameters:
  • id (int) – Menu item identifier.
  • label (string) – Menu item label.

Note

Use only after the menubar has been associated with a frame.

See also

GetLabel



SetLabelTop(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.

Deprecated since version 4.0.1: This function has been deprecated in favour of SetMenuLabel .

Note

Use only after the menubar has been associated with a frame.

See also

GetLabelTop



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.

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



Menus

See GetMenus and SetMenus