********** wx.MenuBar ********** Inheritance diagram for `wx.MenuBar`: | .. inheritance-diagram:: wx.MenuBar | Description =========== A menu bar is a series of menus accessible from the top of a frame. .. seealso:: `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. Derived From ^^^^^^^^^^^^^ * `wx.Window `_ * `wx.EvtHandler `_ * `wx.Object `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `Append <#Append>`_ * `Attach <#Attach>`_ * `Check <#Check>`_ * `Detach <#Detach>`_ * `EnableTop <#EnableTop>`_ * `FindItemById <#FindItemById>`_ * `FindMenu <#FindMenu>`_ * `FindMenuItem <#FindMenuItem>`_ * `GetAutoWindowMenu <#GetAutoWindowMenu>`_ * `GetFrame <#GetFrame>`_ * `GetHelpString <#GetHelpString>`_ * `GetLabelTop <#GetLabelTop>`_ * `GetMenu <#GetMenu>`_ * `GetMenuCount <#GetMenuCount>`_ * `GetMenuLabel <#GetMenuLabel>`_ * `GetMenuLabelText <#GetMenuLabelText>`_ * `GetMenus <#GetMenus>`_ * `Insert <#Insert>`_ * `IsAttached <#IsAttached>`_ * `IsChecked <#IsChecked>`_ * `IsEnabledTop <#IsEnabledTop>`_ * `MacSetCommonMenuBar <#MacSetCommonMenuBar>`_ * `Remove <#Remove>`_ * `Replace <#Replace>`_ * `SetAutoWindowMenu <#SetAutoWindowMenu>`_ * `SetHelpString <#SetHelpString>`_ * `SetLabelTop <#SetLabelTop>`_ * `SetMenuLabel <#SetMenuLabel>`_ * `SetMenus <#SetMenus>`_ * `UpdateMenus <#UpdateMenus>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Frame <#Frame>`_ * `MenuCount <#MenuCount>`_ * `Menus <#Menus>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(style=0) Default constructor. **Parameters:** * `style` (long): If ``wx.MB_DOCKABLE`` the menu bar can be detached (wxGTK only). | **Returns:** `wx.MenuBar `_ -------- .. method:: 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` .. seealso:: `Insert <#Insert>`_ -------- .. method:: Attach(frame) | **Parameters:** * `frame` (`wx.Frame `_) -------- .. method:: 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. -------- .. method:: Detach() `No docstrings available for this method.` -------- .. 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. -------- .. method:: 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. -------- .. method:: FindItemById(id) Finds the menu item object associated with the given menu item identifier. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `wx.MenuItem `_ -------- .. method:: 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` -------- .. method:: 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. -------- .. method:: GetAutoWindowMenu() `No docstrings available for this method.` -------- .. method:: GetFrame() `No docstrings available for this method.` -------- .. method:: GetHelpString(id) Gets the help string associated with the menu item identifier. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `string` .. seealso:: `SetHelpString <#SetHelpString>`_ -------- .. method:: 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 <#GetMenuLabel>`_ and `GetMenuLabelText <#GetMenuLabelText>`_. .. seealso:: `wx.MenuBar.SetLabelTop `_ -------- .. method:: 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 `_ -------- .. method:: GetMenuCount() Returns the number of menus in this menubar. | **Returns:** `int` -------- .. method:: 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. .. seealso:: `GetMenuLabelText <#GetMenuLabelText>`_, `SetMenuLabel <#SetMenuLabel>`_ -------- .. method:: 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. .. seealso:: `GetMenuLabel <#GetMenuLabel>`_, `SetMenuLabel <#SetMenuLabel>`_ -------- .. method:: GetMenus() Return a list of (menu, label) items for the menus in the `wx.MenuBar`. | **Returns:** `list of tuples` -------- .. method:: 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 <#GetMenuCount>`_ is the same as calling `Append <#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` .. seealso:: `Append <#Append>`_ -------- .. method:: IsAttached() `No docstrings available for this method.` -------- .. method:: IsChecked(id) Determines whether an item is checked. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `bool` -------- .. method:: IsEnabledTop(pos) | **Parameters:** * `pos` (int) | **Returns:** `bool` -------- .. method:: MacSetCommonMenuBar(menubar) | **Parameters:** * `menubar` (`wx.MenuBar `_) -------- .. method:: 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 <#Insert>`_ to change the menubar dynamically. **Parameters:** * `pos` (long) | **Returns:** `wx.Menu `_ .. seealso:: `Replace <#Replace>`_ -------- .. method:: 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 `_ .. seealso:: `Insert <#Insert>`_, `Remove <#Remove>`_ -------- .. method:: SetAutoWindowMenu(enable) | **Parameters:** * `enable` (bool) -------- .. method:: 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. .. seealso:: `GetHelpString <#GetHelpString>`_ -------- .. method:: 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 <#SetMenuLabel>`_. .. seealso:: `GetLabelTop <#GetLabelTop>`_ -------- .. method:: 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. -------- .. method:: SetMenus(items) Clear and add new menus to the `wx.MenuBar` from a list of (menu, label) items. **Parameters:** * `items` (list of tuples) -------- .. method:: UpdateMenus() `No docstrings available for this method.` -------- Properties ^^^^^^^^^^ .. attribute:: Frame See `GetFrame <#GetFrame>`_ .. attribute:: MenuCount See `GetMenuCount <#GetMenuCount>`_ .. attribute:: Menus See `GetMenus <#GetMenus>`_ and `SetMenus <#SetMenus>`_