wx.MenuBar

Inheritance diagram for wx.MenuBar:



Description

A menu bar is a series of menus accessible from the top of a frame.

See also

wx.Menu

Event Handling

To respond to a menu selection, provide a handler for wx.EVT_MENU, in the frame that contains the menu bar. If you have a toolbar which uses the same identifiers as your wx.EVT_MENU entries, events from the toolbar will also be processed by your wx.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 wx.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.

Properties Summary

Class API

Methods

__init__(style=0)

Default constructor.

Parameters:

  • style (long): If wx.MB_DOCKABLE the menu bar can be detached (wxGTK only).

Returns:

wx.MenuBar


Append(menu, title)

Adds the item to the end of the menu bar.

Returns True if succesful, False if some error occurred.

Parameters:

  • menu (wx.Menu): The menu to add. Do not deallocate this menu after calling Append.
  • title (string): The title of the menu.

Returns:

bool

See also

Insert


Attach(frame)

Parameters:


Check(id, check)

Checks or unchecks a menu item.

Parameters:

  • id (int): The menu item identifier.
  • check (bool): Whether to check or uncheck the menu item.

Note

Only use this when the menu bar has been associated with a frame; otherwise, use the wx.Menu equivalent call.


Detach()
No docstrings available for this method.

Enable(id, enable)

Enables or disables a whole menu.

Parameters:

  • id (int): The menu identifier.
  • 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; otherwise, use the wx.Menu equivalent call.


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


FindItemById(id)

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

Parameters:

  • id (int): The menu item identifier.

Returns:

wx.MenuItem


FindMenu(title)

Returns the index of the menu with the given title or wx.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)

Returns:

int


FindMenuItem(menu, item)

Finds the menu item id for a menu name/menu item string pair.

Parameters:

  • menu (string)
  • item (string)

Returns:

int

Note

Any special menu codes are stripped out of source and target strings before matching.


GetAutoWindowMenu()
No docstrings available for this method.

GetFrame()
No docstrings available for this method.

GetHelpString(id)

Gets the help string associated with the menu item identifier.

Parameters:

  • id (int): The menu item identifier.

Returns:

string

See also

SetHelpString


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

Returns:

string

Note

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

Warning

This function is deprecated in favour of GetMenuLabel and GetMenuLabelText.


GetMenu(pos)

Returns the menu at pos (zero-based).

Parameters:

  • pos (int): Position of the menu on the menu bar, starting from zero.

Returns:

wx.Menu


GetMenuCount()

Returns the number of menus in this menubar.


Returns:

int


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

Returns:

string

Note

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


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

Returns:

string

Note

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


GetMenus()

Return a list of (menu, label) items for the menus in the wx.MenuBar.


Returns:

list of tuples


Insert(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 (long): 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.

Returns:

bool

See also

Append


IsAttached()
No docstrings available for this method.

IsChecked(id)

Determines whether an item is checked.

Parameters:

  • id (int): The menu item identifier.

Returns:

bool


IsEnabledTop(pos)

Parameters:

  • pos (int)

Returns:

bool


MacSetCommonMenuBar(menubar)

Parameters:


Remove(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 (long)

Returns:

wx.Menu

See also

Replace


Replace(pos, menu, title)

Replaces the menu at the given position with another one.

Parameters:

  • pos (long): The position of the new menu in the menu bar
  • menu (wx.Menu): The menu to add.
  • title (string): The title of the menu.

Returns:

wx.Menu

See also

Insert, Remove


SetAutoWindowMenu(enable)

Parameters:

  • enable (bool)

SetHelpString(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


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

Warning

This function has been deprecated in favour of SetMenuLabel.

See also

GetLabelTop


SetMenuLabel(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(items)

Clear and add new menus to the wx.MenuBar from a list of (menu, label) items.

Parameters:

  • items (list of tuples)

UpdateMenus()
No docstrings available for this method.

Properties

Frame
See GetFrame
See GetMenuCount
See GetMenus and SetMenus