******* wx.Menu ******* Inheritance diagram for `wx.Menu`: | .. inheritance-diagram:: wx.Menu | Description =========== A menu is a popup (or pull down) list of items, one of which may be selected before the menu goes away (clicking elsewhere dismisses the menu). Menus may be used to construct either menu bars or popup menus. A menu item has an integer ID associated with it which can be used to identify the selection, or to change the menu item in some way. A menu item with a special identifier -1 is a separator item and doesn't have an associated command but just makes a separator line appear in the menu. .. note:: Please note that ``wx.ID_ABOUT`` and ``wx.ID_EXIT`` are predefined by wxWidgets and have a special meaning since entries using these IDs will be taken out of the normal menus under MacOS X and will be inserted into the system menu (following the appropriate MacOS X interface guideline). On PalmOS ``wx.ID_EXIT`` is disabled according to Palm OS Companion guidelines. Menu items may be either normal items, check items or radio items. Normal items don't have any special properties while the check items have a boolean flag associated to them and they show a checkmark in the menu when the flag is set. wxWidgets automatically toggles the flag value when the item is clicked and its value may be retrieved using either `IsChecked <#IsChecked>`_ method of wx.Menu or `wx.MenuBar` itself or by using `wx.Event.IsChecked <../Events/wx.CommandEvent.html#IsChecked>`_ when you get the menu notification for the item in question. The radio items are similar to the check items except that all the other items in the same radio group are unchecked when a radio item is checked. The radio group is formed by a contiguous range of radio items, i.e. it starts at the first item of this kind and ends with the first item of a different kind (or the end of the menu). .. note:: Notice that because the radio groups are defined in terms of the item positions inserting or removing the items in the menu containing the radio items risks to not work correctly. .. note:: Finally note that radio items are not supported under Motif. .. seealso:: `wx.MenuBar `_, `wx.Window.PopupMenu `_, `wx.FileHistory `_ Derived From ^^^^^^^^^^^^^ * `wx.EvtHandler `_ * `wx.Object `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `Append <#Append>`_ * `AppendCheckItem <#AppendCheckItem>`_ * `AppendItem <#AppendItem>`_ * `AppendMenu <#AppendMenu>`_ * `AppendRadioItem <#AppendRadioItem>`_ * `AppendSeparator <#AppendSeparator>`_ * `AppendSubMenu <#AppendSubMenu>`_ * `Attach <#Attach>`_ * `Break <#Break>`_ * `Check <#Check>`_ * `Delete <#Delete>`_ * `DeleteItem <#DeleteItem>`_ * `DestroyId <#DestroyId>`_ * `DestroyItem <#DestroyItem>`_ * `Detach <#Detach>`_ * `Enable <#Enable>`_ * `FindItem <#FindItem>`_ * `FindItemById <#FindItemById>`_ * `FindItemByPosition <#FindItemByPosition>`_ * `GetEventHandler <#GetEventHandler>`_ * `GetHelpString <#GetHelpString>`_ * `GetInvokingWindow <#GetInvokingWindow>`_ * `GetLabel <#GetLabel>`_ * `GetLabelText <#GetLabelText>`_ * `GetMenuBar <#GetMenuBar>`_ * `GetMenuItemCount <#GetMenuItemCount>`_ * `GetMenuItems <#GetMenuItems>`_ * `GetParent <#GetParent>`_ * `GetStyle <#GetStyle>`_ * `GetTitle <#GetTitle>`_ * `Insert <#Insert>`_ * `InsertCheckItem <#InsertCheckItem>`_ * `InsertItem <#InsertItem>`_ * `InsertMenu <#InsertMenu>`_ * `InsertRadioItem <#InsertRadioItem>`_ * `InsertSeparator <#InsertSeparator>`_ * `IsAttached <#IsAttached>`_ * `IsChecked <#IsChecked>`_ * `IsEnabled <#IsEnabled>`_ * `Prepend <#Prepend>`_ * `PrependCheckItem <#PrependCheckItem>`_ * `PrependItem <#PrependItem>`_ * `PrependMenu <#PrependMenu>`_ * `PrependRadioItem <#PrependRadioItem>`_ * `PrependSeparator <#PrependSeparator>`_ * `Remove <#Remove>`_ * `RemoveItem <#RemoveItem>`_ * `SetEventHandler <#SetEventHandler>`_ * `SetHelpString <#SetHelpString>`_ * `SetInvokingWindow <#SetInvokingWindow>`_ * `SetLabel <#SetLabel>`_ * `SetParent <#SetParent>`_ * `SetTitle <#SetTitle>`_ * `UpdateUI <#UpdateUI>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `EventHandler <#EventHandler>`_ * `HelpString <#HelpString>`_ * `InvokingWindow <#InvokingWindow>`_ * `MenuBar <#MenuBar>`_ * `MenuItemCount <#MenuItemCount>`_ * `MenuItems <#MenuItems>`_ * `Parent <#Parent>`_ * `Style <#Style>`_ * `Title <#Title>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(title="", style=0) Construct a `wx.Menu` object. **Parameters:** * `title` (string): A title for the popup menu: the empty string denotes no title. * `style` (long): If set to ``wx.MENU_TEAROFF``, the menu will be detachable (wxGTK only). | **Returns:** `wx.Menu `_ -------- .. method:: Append(id, string, helpStr="", checkable=false) Adds a menu item object. This is the most generic variant of `Append()` method because it may be used for both items (including separators) and submenus and because you can also specify various extra properties of a menu item this way, such as bitmaps and fonts. This command can be used after the menu has been shown, as well as on initial creation of a menu or menubar. The `string` string for the normal menu items (not submenus or separators) may include the accelerator which can be used to activate the menu item from keyboard. The accelerator string follows the item label and is separated from it by a ``TAB`` stringacter (``'\t'``). Its general syntax is any combination of ``CTRL``, ``ALT`` and ``SHIFT`` strings (case doesn't matter) separated by either ``'-'`` or ``'+'`` stringacters and followed by the accelerator itself. The accelerator may be any alphanumeric string character, any function key (from ``F1`` to ``F12``) or one of the special string characters listed in the table below (again, case doesn't matter): ======================================== =========================================== Key Description ======================================== =========================================== ``DEL`` or ``DELETE`` Delete key ``INS`` or ``INSERT`` Insert key ``ENTER`` or ``RETURN`` Enter key ``PGUP`` PageUp key ``PGDN`` PageDown key ``LEFT`` Left cursor arrow key ``RIGHT`` Right cursor arrow key ``UP`` Up cursor arrow key ``DOWN`` Down cursor arrow key ``HOME`` Home key ``END`` End key ``SPACE`` Space ``TAB`` Tab key ``ESC`` or ``ESCAPE`` Escape key (Windows only) ======================================== =========================================== | **Parameters:** * `id` (int): The menu command identifier. * `string` (string): The string to appear on the menu item. * `helpStr` (string): An optional help string associated with the item. By default, the handler for the ``wx.EVT_MENU_HIGHLIGHT`` event displays this string in the status line. * `checkable` (bool): whether the appended item is check-style or not. | **Returns:** `wx.MenuItem `_ .. seealso:: `AppendSeparator <#AppendSeparator>`_, `AppendCheckItem <#AppendCheckItem>`_, `AppendRadioItem <#AppendRadioItem>`_, `AppendSubMenu <#AppendSubMenu>`_, `Insert <#Insert>`_, `SetLabel <#SetLabel>`_, `GetHelpString <#GetHelpString>`_, `SetHelpString <#SetHelpString>`_, `wx.MenuItem `_ -------- .. method:: AppendCheckItem(id, item, helpString="") Adds a checkable item to the end of the menu. **Parameters:** * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Append <#Append>`_, `InsertCheckItem <#InsertCheckItem>`_ -------- .. method:: AppendItem(item) Appends a `wx.MenuItem `_ to the current menu. **Parameters:** * `item` (`wx.MenuItem `_) | **Returns:** `wx.MenuItem `_ -------- .. method:: AppendMenu(id, text, submenu, help="") Appends a submenu to the current menu. **Parameters:** * `id` (int) * `text` (string) * `submenu` (`wx.Menu `_) * `help` (string) | **Returns:** `wx.MenuItem `_ -------- .. method:: AppendRadioItem(id, item, helpString="") Adds a radio item to the end of the menu. All consequent radio items form a group and when an item in the group is checked, all the others are automatically unchecked. **Parameters:** * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Append <#Append>`_, `InsertRadioItem <#InsertRadioItem>`_ -------- .. method:: AppendSeparator() Adds a separator to the end of the menu. | **Returns:** `wx.MenuItem `_ .. seealso:: `Append <#Append>`_, `InsertSeparator <#InsertSeparator>`_ -------- .. method:: AppendSubMenu(submenu, text, help="") Adds the given `submenu` to this menu. `text` is the text shown in the menu for it and `help` is the help string shown in the status bar when the submenu item is selected. **Parameters:** * `submenu` (`wx.Menu `_) * `text` (string) * `help` (string) | **Returns:** `wx.MenuItem `_ -------- .. method:: Attach(menubar) | **Parameters:** * `menubar` (`wx.MenuBar `_) -------- .. method:: Break() Inserts a break in a menu, causing the next appended item to appear in a new column. -------- .. method:: Check(id, check) Checks or unchecks the menu item. **Parameters:** * `id` (int): The menu item identifier. * `check` (bool): Whether to check or uncheck the menu item. .. seealso:: `IsChecked <#IsChecked>`_ -------- .. method:: Delete(id) Deletes the menu item from the menu. If the item is a submenu, it will **not** be deleted. Use `DestroyId <#DestroyId>`_ if you want to delete a submenu. **Parameters:** * `id` (int): The menu item identifier. .. seealso:: `FindItem <#FindItem>`_, `DestroyId <#DestroyId>`_, `Remove <#Remove>`_ -------- .. method:: DeleteItem(item) Deletes the menu item from the menu. If the item is a submenu, it will **not** be deleted. Use `DestroyItem <#DestroyItem>`_ if you want to delete a submenu. **Parameters:** * `item` (`wx.MenuItem `_) | **Returns:** `bool` .. seealso:: `FindItem <#FindItem>`_, `DestroyItem <#DestroyItem>`_, `Remove <#Remove>`_ -------- .. method:: DestroyId(id) Deletes the menu item with id `id` from the menu. If the item is a submenu, it will be deleted. Use `Remove <#Remove>`_ if you want to keep the submenu (for example, to reuse it later). **Parameters:** * `id` (int) | **Returns:** `bool` -------- .. method:: DestroyItem(item) Deletes the menu item from the menu. If the item is a submenu, it will be deleted. Use `RemoveItem <#RemoveItem>`_ if you want to keep the submenu (for example, to reuse it later). **Parameters:** * `item` (`wx.MenuItem `_) | **Returns:** `bool` -------- .. method:: Detach() `No docstrings available for this method.` -------- .. method:: Enable(id, enable) Enables or disables (greys out) a menu item. **Parameters:** * `id` (int) * `enable` (bool) .. seealso:: `IsEnabled <#IsEnabled>`_ -------- .. method:: FindItem(item) Finds the menu item object associated with the given menu item. **Parameters:** * `item` (string) | **Returns:** `int` .. note:: Any special menu codes are stripped out of source and target strings before matching. -------- .. method:: FindItemById(id) Finds the menu item object associated with the given menu item identifier. **Parameters:** * `id` (int) | **Returns:** `wx.MenuItem `_ -------- .. method:: FindItemByPosition(position) Returns the `wx.MenuItem `_ given a position in the menu. **Parameters:** * `position` (long) | **Returns:** `wx.MenuItem `_ -------- .. method:: GetEventHandler() `No docstrings available for this method.` -------- .. method:: GetHelpString(id) Returns the help string associated with a menu item. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `string` .. seealso:: `SetHelpString <#SetHelpString>`_, `Append <#Append>`_ -------- .. method:: GetInvokingWindow() `No docstrings available for this method.` -------- .. method:: GetLabel(itemid) Returns a menu item label, including any mnemonics and accelerators. **Parameters:** * `itemid` (int) | **Returns:** `string` .. seealso:: `GetLabelText <#GetLabelText>`_, `SetLabel <#SetLabel>`_ -------- .. method:: GetLabelText(itemid) Returns a menu item label, without any of the original mnemonics and accelerators. **Parameters:** * `itemid` (int) | **Returns:** `string` .. seealso:: `GetLabel <#GetLabel>`_, `SetLabel <#SetLabel>`_ -------- .. method:: GetMenuBar() `No docstrings available for this method.` -------- .. method:: GetMenuItemCount() Returns the number of items in the menu. | **Returns:** `long` -------- .. method:: GetMenuItems() Returns the list of items in the menu. `wx.MenuItemList` is a pseudo-template list class containing `wx.MenuItem `_ pointers. | **Returns:** `wx.MenuItemList` -------- .. method:: GetParent() `No docstrings available for this method.` -------- .. method:: GetStyle() `No docstrings available for this method.` -------- .. method:: GetTitle() Returns the title of the menu. | **Returns:** `string` .. note:: This is relevant only to popup menus, use `wx.MenuBar.GetMenuLabel `_ for the menus in the menubar. .. seealso:: `SetTitle <#SetTitle>`_ -------- .. method:: Insert(pos, id, text="", help="", kind=wx.ITEM_NORMAL) Inserts the given `item` before the position `pos`. Inserting the item at position `GetMenuItemCount <#GetMenuItemCount>`_ is the same as appending it. **Parameters:** * `pos` (long) * `id` (int) * `help` (string) * `kind` (int) | **Returns:** `wx.MenuItem `_ .. seealso:: `Append <#Append>`_, `Prepend <#Prepend>`_ -------- .. method:: InsertCheckItem(pos, id, item, helpString="") Inserts a checkable item at the given position. **Parameters:** * `pos` (long) * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Insert <#Insert>`_, `AppendCheckItem <#AppendCheckItem>`_ -------- .. method:: InsertItem(pos, item) Inserts the given menu item at the specified position. **Parameters:** * `pos` (int) * `item` (`wx.MenuItem `_) | **Returns:** `wx.MenuItem `_ -------- .. method:: InsertMenu(pos, id, text, submenu, help="") | **Parameters:** * `pos` (int) * `id` (int) * `text` (string) * `submenu` (`wx.Menu `_) * `help` (string) | **Returns:** `wx.MenuItem `_ -------- .. method:: InsertRadioItem(pos, id, item, helpString="") Inserts a radio item at the given position. **Parameters:** * `pos` (long) * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Insert <#Insert>`_, `AppendRadioItem <#AppendRadioItem>`_ -------- .. method:: InsertSeparator(pos) Inserts a separator at the given position. **Parameters:** * `pos` (long) | **Returns:** `wx.MenuItem `_ .. seealso:: `Insert <#Insert>`_, `AppendSeparator <#AppendSeparator>`_ -------- .. method:: IsAttached() `No docstrings available for this method.` -------- .. method:: IsChecked(id) Determines whether a menu item is checked. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `bool` .. seealso:: `Check <#Check>`_ -------- .. method:: IsEnabled(id) Determines whether a menu item is enabled. **Parameters:** * `id` (int): The menu item identifier. | **Returns:** `bool` .. seealso:: `Enable <#Enable>`_ -------- .. method:: Prepend(id, text="", help="", kind=wx.ITEM_NORMAL) Prepend the given menu item with id `id` at position 0. **Parameters:** * `id` (int) * `text` (string) * `help` (string) * `kind` (int) | **Returns:** `wx.MenuItem `_ .. seealso:: `Append <#Append>`_, `Insert <#Insert>`_ -------- .. method:: PrependCheckItem(id, item, helpString="") Inserts a checkable item at position 0. **Parameters:** * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Prepend <#Prepend>`_, `AppendCheckItem <#AppendCheckItem>`_ -------- .. method:: PrependItem(item) Prepends a menu item at position 0. **Parameters:** * `item` (`wx.MenuItem `_) | **Returns:** `wx.MenuItem `_ -------- .. method:: PrependMenu(id, text, submenu, help="") | **Parameters:** * `id` (int) * `text` (string) * `submenu` (`wx.Menu `_) * `help` (string) | **Returns:** `wx.MenuItem `_ -------- .. method:: PrependRadioItem(id, item, helpString="") Inserts a radio item at position 0. **Parameters:** * `id` (int) * `item` (string) * `helpString` (string) | **Returns:** `wx.MenuItem `_ .. seealso:: `Prepend <#Prepend>`_, `AppendRadioItem <#AppendRadioItem>`_ -------- .. method:: PrependSeparator() Inserts a separator at position 0. | **Returns:** `wx.MenuItem `_ .. seealso:: `Prepend <#Prepend>`_, `AppendSeparator <#AppendSeparator>`_ -------- .. method:: Remove(id) Removes the menu item from the menu but doesn't delete the associated C++ object. This allows to reuse the same item later by adding it back to the menu (especially useful with submenus). **Parameters:** * `id` (int): The identifier of the menu item to remove. | **Returns:** `wx.MenuItem `_ -------- .. method:: RemoveItem(item) Removes the menu item from the menu but doesn't delete the associated C++ object. This allows to reuse the same item later by adding it back to the menu (especially useful with submenus). **Parameters:** * `item` (`wx.MenuItem `_) | **Returns:** `wx.MenuItem `_ -------- .. method:: SetEventHandler(handler) | **Parameters:** * `handler` (`wx.EvtHandler `_) -------- .. method:: SetHelpString(id, helpString) Sets an item's help string. **Parameters:** * `id` (int): The menu item identifier. * `helpString` (string): The help string to set. .. seealso:: `GetHelpString <#GetHelpString>`_ -------- .. method:: SetInvokingWindow(win) | **Parameters:** * `win` (`wx.Window `_) -------- .. method:: SetLabel(id, label) Sets the label of a menu item. **Parameters:** * `id` (int): The menu item identifier. * `label` (string): The menu item label to set. .. seealso:: `Append <#Append>`_, `GetLabel <#GetLabel>`_ -------- .. method:: SetParent(parent) | **Parameters:** * `parent` (`wx.Menu `_) -------- .. method:: SetTitle(title) Sets the title of the menu. **Parameters:** * `title` (string): The title to set. .. note:: This is relevant only to popup menus, use `wx.MenuBar.SetLabelTop `_ for the menus in the menubar. .. seealso:: `GetTitle <#GetTitle>`_ -------- .. method:: UpdateUI(source=None) Sends events to `source` (or owning window if ``None``) to update the menu UI. This is called just before the menu is popped up with `wx.Window.PopupMenu `_, but the application may call it at other times if required. **Parameters:** * `source` (`wx.EvtHandler `_) -------- Properties ^^^^^^^^^^ .. attribute:: EventHandler See `GetEventHandler <#GetEventHandler>`_ and `SetEventHandler <#SetEventHandler>`_ .. attribute:: HelpString See `GetHelpString <#GetHelpString>`_ and `SetHelpString <#SetHelpString>`_ .. attribute:: InvokingWindow See `GetInvokingWindow <#GetInvokingWindow>`_ and `SetInvokingWindow <#SetInvokingWindow>`_ .. attribute:: MenuBar See `GetMenuBar <#GetMenuBar>`_ .. attribute:: MenuItemCount See `GetMenuItemCount <#GetMenuItemCount>`_ .. attribute:: MenuItems See `GetMenuItems <#GetMenuItems>`_ .. attribute:: Parent See `GetParent <#GetParent>`_ and `SetParent <#SetParent>`_ .. attribute:: Style See `GetStyle <#GetStyle>`_ .. attribute:: Title See `GetTitle <#GetTitle>`_ and `SetTitle <#SetTitle>`_