*********** wx.MenuItem *********** Inheritance diagram for `wx.MenuItem`: | .. inheritance-diagram:: wx.MenuItem | Description =========== A menu item represents an item in a menu. Note that you usually don't have to deal with it directly as `wx.Menu `_ methods usually construct an object of this class for you. .. note:: Please note that the methods related to fonts and bitmaps are currently only implemented for Windows and GTK+. .. seealso:: `wx.MenuBar `_, `wx.Menu `_ Derived From ^^^^^^^^^^^^^ * `wx.Object `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `Check <#Check>`_ * `Enable <#Enable>`_ * `GetAccel <#GetAccel>`_ * `GetBackgroundColour <#GetBackgroundColour>`_ * `GetBitmap <#GetBitmap>`_ * `GetDefaultMarginWidth <#GetDefaultMarginWidth>`_ * `GetDisabledBitmap <#GetDisabledBitmap>`_ * `GetFont <#GetFont>`_ * `GetHelp <#GetHelp>`_ * `GetId <#GetId>`_ * `GetItemLabel <#GetItemLabel>`_ * `GetItemLabelText <#GetItemLabelText>`_ * `GetKind <#GetKind>`_ * `GetLabel <#GetLabel>`_ * `GetLabelFromText <#GetLabelFromText>`_ * `GetLabelText <#GetLabelText>`_ * `GetMarginWidth <#GetMarginWidth>`_ * `GetMenu <#GetMenu>`_ * `GetSubMenu <#GetSubMenu>`_ * `GetText <#GetText>`_ * `GetTextColour <#GetTextColour>`_ * `IsCheckable <#IsCheckable>`_ * `IsChecked <#IsChecked>`_ * `IsEnabled <#IsEnabled>`_ * `IsOwnerDrawn <#IsOwnerDrawn>`_ * `IsSeparator <#IsSeparator>`_ * `IsSubMenu <#IsSubMenu>`_ * `ResetOwnerDrawn <#ResetOwnerDrawn>`_ * `SetAccel <#SetAccel>`_ * `SetBackgroundColour <#SetBackgroundColour>`_ * `SetBitmap <#SetBitmap>`_ * `SetBitmaps <#SetBitmaps>`_ * `SetCheckable <#SetCheckable>`_ * `SetDisabledBitmap <#SetDisabledBitmap>`_ * `SetFont <#SetFont>`_ * `SetHelp <#SetHelp>`_ * `SetId <#SetId>`_ * `SetItemLabel <#SetItemLabel>`_ * `SetKind <#SetKind>`_ * `SetMarginWidth <#SetMarginWidth>`_ * `SetMenu <#SetMenu>`_ * `SetOwnerDrawn <#SetOwnerDrawn>`_ * `SetSubMenu <#SetSubMenu>`_ * `SetText <#SetText>`_ * `SetTextColour <#SetTextColour>`_ * `Toggle <#Toggle>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Accel <#Accel>`_ * `BackgroundColour <#BackgroundColour>`_ * `Bitmap <#Bitmap>`_ * `DisabledBitmap <#DisabledBitmap>`_ * `Font <#Font>`_ * `Help <#Help>`_ * `Id <#Id>`_ * `ItemLabel <#ItemLabel>`_ * `Kind <#Kind>`_ * `Label <#Label>`_ * `MarginWidth <#MarginWidth>`_ * `Menu <#Menu>`_ * `SubMenu <#SubMenu>`_ * `Text <#Text>`_ * `TextColour <#TextColour>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(parentMenu=None, id=wx.ID_SEPARATOR, text="", help="", kind=wx.ITEM_NORMAL, subMenu=None) Constructs a `wx.MenuItem` object. Menu items can be standard, or "stock menu items", or custom. For the standard menu items (such as commands to open a file, exit the program and so on) it is enough to specify just the stock ID and leave text and `helpString` empty. In fact, leaving at least text empty for the stock menu items is strongly recommended as they will have appearance and keyboard interface (including standard accelerators) familiar to the user. For the custom (non-stock) menu items, text must be specified and while `helpString` may be left empty, it's recommended to pass the item description (which is automatically shown by the library in the status bar when the menu item is selected) in this parameter. Finally note that you can e.g. use a stock menu label without using its stock help string:: # use all stock properties: helpMenu.Append(wx.ID_ABOUT) # use the stock label and the stock accelerator but not the stock help string: helpMenu.Append(wx.ID_ABOUT, "", "My custom help string") # use all stock properties except for the bitmap: mymenu = wx.MenuItem(helpMenu, wxID_ABOUT) mymenu.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_WARNING)) helpMenu.AppendItem(mymenu) That is, stock properties are set independently one from the other. **Parameters:** * `parentMenu` (`wx.Menu `_): Menu that the menu item belongs to. * `id` (int): Identifier for this menu item, or ``wx.ID_SEPARATOR`` to indicate a separator. * `text` (string): Text for the menu item, as shown on the menu. An accelerator key can be specified using the ampersand ``&`` character. In order to embed an ampersand character in the menu item text, the ampersand must be doubled. * `help` (string): Optional help string that will be shown on the status bar. * `kind` (int): May be ``wx.ITEM_SEPARATOR``, ``wx.ITEM_NORMAL``, ``wx.ITEM_CHECK`` or ``wx.ITEM_RADIO``. * `subMenu` (`wx.Menu `_): If not ``None``, indicates that the menu item is a submenu. | **Returns:** `wx.MenuItem `_ -------- .. method:: Check(check=True) Checks or unchecks the menu item. **Parameters:** * `check` (bool) .. note:: Note that this only works when the item is already appended to a menu. -------- .. method:: Enable(enable=True) Enables or disables the menu item. **Parameters:** * `enable` (bool) -------- .. method:: GetAccel() `No docstrings available for this method.` -------- .. method:: GetBackgroundColour() Returns the background colour associated with the menu item (Windows only). | **Returns:** `wx.Colour `_ -------- .. method:: GetBitmap(checked=True) Returns the checked or unchecked bitmap (Windows only). **Parameters:** * `checked` (bool) | **Returns:** `wx.Bitmap `_ -------- .. method:: GetDefaultMarginWidth() `No docstrings available for this method.` -------- .. method:: GetDisabledBitmap() `No docstrings available for this method.` -------- .. method:: GetFont() Returns the font associated with the menu item (Windows only). | **Returns:** `wx.Font `_ -------- .. method:: GetHelp() Returns the help string associated with the menu item. | **Returns:** `string` -------- .. method:: GetId() Returns the menu item identifier. | **Returns:** `int` -------- .. method:: GetItemLabel() Returns the text associated with the menu item including any accelerator characters that were passed to the constructor or `SetItemLabel <#SetItemLabel>`_. | **Returns:** `string` .. seealso:: `GetItemLabelText <#GetItemLabelText>`_, `GetLabelText <#GetLabelText>`_ -------- .. method:: GetItemLabelText() Returns the text associated with the menu item, without any accelerator characters. | **Returns:** `string` .. seealso:: `GetItemLabel <#GetItemLabel>`_, `GetLabelText <#GetLabelText>`_ -------- .. method:: GetKind() Returns the item kind, one of ``wx.ITEM_SEPARATOR``, ``wx.ITEM_NORMAL``, ``wx.ITEM_CHECK`` or ``wx.ITEM_RADIO``. | **Returns:** `int` -------- .. method:: GetLabel(text) Returns the text associated with the menu item without any accelerator characters it might contain. **Parameters:** * `text` (string) | **Returns:** `string` .. warning:: This function is deprecated in favour of `GetItemLabelText <#GetItemLabelText>`_. .. seealso:: `GetText <#GetText>`_, `GetLabelFromText <#GetLabelFromText>`_ -------- .. method:: GetLabelFromText(text) Strips all accelerator characters and mnemonics from the given `text`. For example:: menuItem.GetLabelFromText("&Hello\tCtrl-H") will return just ``"Hello"``. **Parameters:** * `text` (string) | **Returns:** `string` .. warning:: This function is deprecated; please use `GetLabelText <#GetLabelText>`_ instead. .. seealso:: `GetText <#GetText>`_, `GetLabel <#GetLabel>`_ -------- .. method:: GetLabelText(text) Strips all accelerator characters and mnemonics from the given `text`. For example:: menuItem.GetLabelText("&Hello\tCtrl-H") will return just ``"Hello"``. **Parameters:** * `text` (string) | **Returns:** `string` .. seealso:: `GetItemLabelText <#GetItemLabelText>`_, `GetItemLabel <#GetItemLabel>`_ -------- .. method:: GetMarginWidth() Gets the width of the menu item checkmark bitmap (Windows only). | **Returns:** `int` -------- .. method:: GetMenu() Returns the menu this menu item is in, or ``None`` if this menu item is not attached. | **Returns:** `wx.Menu `_ -------- .. method:: GetSubMenu() Returns the submenu associated with the menu item, or ``None`` if there isn't one. | **Returns:** `wx.Menu `_ -------- .. method:: GetText() Returns the text associated with the menu item, such as it was passed to the `wx.MenuItem` constructor, i.e. with any accelerator characters it may contain. | **Returns:** `string` .. warning:: This function is deprecated in favour of `GetItemLabel <#GetItemLabel>`_. .. seealso:: `GetLabel <#GetLabel>`_, `GetLabelFromText <#GetLabelFromText>`_ -------- .. method:: GetTextColour() Returns the text colour associated with the menu item (Windows only). | **Returns:** `wx.Colour `_ -------- .. method:: IsCheckable() Returns ``True`` if the item is checkable. | **Returns:** `bool` -------- .. method:: IsChecked() Returns ``True`` if the item is checked. | **Returns:** `bool` -------- .. method:: IsEnabled() Returns ``True`` if the item is enabled. | **Returns:** `bool` -------- .. method:: IsOwnerDrawn() `No docstrings available for this method.` -------- .. method:: IsSeparator() Returns ``True`` if the item is a separator. | **Returns:** `bool` -------- .. method:: IsSubMenu() Returns ``True`` if the item is a submenu. | **Returns:** `bool` -------- .. method:: ResetOwnerDrawn() `No docstrings available for this method.` -------- .. method:: SetAccel(accel) | **Parameters:** * `accel` (`wx.AcceleratorEntry `_) -------- .. method:: SetBackgroundColour(colour) Sets the background colour associated with the menu item (Windows only). **Parameters:** * `colour` (`wx.Colour `_) -------- .. method:: SetBitmap(bmp) Sets the bitmap for the menu item (Windows and GTK+ only). It is equivalent to `SetBitmaps <#SetBitmaps>`_ (bmp, `wx.NullBitmap`). **Parameters:** * `bmp` (`wx.Bitmap `_) -------- .. method:: SetBitmaps(checked, unchecked=wx.NullBitmap) Sets the checked/unchecked bitmaps for the menu item (Windows only). The first bitmap is also used as the single bitmap for uncheckable menu items. **Parameters:** * `checked` (`wx.Bitmap `_) * `unchecked` (`wx.Bitmap `_) -------- .. method:: SetCheckable(checkable) Sets the menu item as checkable. **Parameters:** * `checkable` (bool) -------- .. method:: SetDisabledBitmap(bmpDisabled) | **Parameters:** * `bmpDisabled` (`wx.Bitmap `_) -------- .. method:: SetFont(font) Sets the font associated with the menu item (Windows only). **Parameters:** * `font` (`wx.Font `_) -------- .. method:: SetHelp(helpString) Sets the help string. **Parameters:** * `helpString` (string) -------- .. method:: SetId(id) Sets the menu item id. **Parameters:** * `id` (int) -------- .. method:: SetItemLabel(label) Sets the label associated with the menu item. **Parameters:** * `label` (string) -------- .. method:: SetKind(kind) Sets the menu item kind, which may be one of ``wx.ITEM_SEPARATOR``, ``wx.ITEM_NORMAL``, ``wx.ITEM_CHECK`` or ``wx.ITEM_RADIO``. **Parameters:** * `kind` (int) -------- .. method:: SetMarginWidth(width) Sets the width of the menu item checkmark bitmap (Windows only). **Parameters:** * `width` (int) -------- .. method:: SetMenu(menu) Sets the parent menu which will contain this menu item. **Parameters:** * `menu` (`wx.Menu `_) -------- .. method:: SetOwnerDrawn(ownerDrawn=True) | **Parameters:** * `ownerDrawn` (bool) -------- .. method:: SetSubMenu(menu) Sets the submenu of this menu item. **Parameters:** * `menu` (`wx.Menu `_) -------- .. method:: SetText(text) Sets the text associated with the menu item. **Parameters:** * `text` (string) .. warning:: This function is deprecated in favour of `SetItemLabel <#SetItemLabel>`_. -------- .. method:: SetTextColour(colour) Sets the text colour associated with the menu item (Windows only). **Parameters:** * `colour` (`wx.Colour `_) -------- .. method:: Toggle() `No docstrings available for this method.` -------- Properties ^^^^^^^^^^ .. attribute:: Accel See `GetAccel <#GetAccel>`_ and `SetAccel <#SetAccel>`_ .. attribute:: BackgroundColour See `GetBackgroundColour <#GetBackgroundColour>`_ and `SetBackgroundColour <#SetBackgroundColour>`_ .. attribute:: Bitmap See `GetBitmap <#GetBitmap>`_ and `SetBitmap <#SetBitmap>`_ .. attribute:: DisabledBitmap See `GetDisabledBitmap <#GetDisabledBitmap>`_ and `SetDisabledBitmap <#SetDisabledBitmap>`_ .. attribute:: Font See `GetFont <#GetFont>`_ and `SetFont <#SetFont>`_ .. attribute:: Help See `GetHelp <#GetHelp>`_ and `SetHelp <#SetHelp>`_ .. attribute:: Id See `GetId <#GetId>`_ and `SetId <#SetId>`_ .. attribute:: ItemLabel See `GetItemLabel <#GetItemLabel>`_ .. attribute:: Kind See `GetKind <#GetKind>`_ and `SetKind <#SetKind>`_ .. attribute:: Label See `GetLabel <#GetLabel>`_ .. attribute:: MarginWidth See `GetMarginWidth <#GetMarginWidth>`_ and `SetMarginWidth <#SetMarginWidth>`_ .. attribute:: Menu See `GetMenu <#GetMenu>`_ and `SetMenu <#SetMenu>`_ .. attribute:: SubMenu See `GetSubMenu <#GetSubMenu>`_ and `SetSubMenu <#SetSubMenu>`_ .. attribute:: Text See `GetText <#GetText>`_ and `SetText <#SetText>`_ .. attribute:: TextColour See `GetTextColour <#GetTextColour>`_ and `SetTextColour <#SetTextColour>`_