wx.MenuItem

Inheritance diagram for wx.MenuItem:



Class API

Methods

__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


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.


Enable(enable=True)

Enables or disables the menu item.

Parameters:

  • enable (bool)

GetAccel()
No docstrings available for this method.

GetBackgroundColour()

Returns the background colour associated with the menu item (Windows only).


Returns:

wx.Colour


GetBitmap(checked=True)

Returns the checked or unchecked bitmap (Windows only).

Parameters:

  • checked (bool)

Returns:

wx.Bitmap


GetDefaultMarginWidth()
No docstrings available for this method.

GetDisabledBitmap()
No docstrings available for this method.

GetFont()

Returns the font associated with the menu item (Windows only).


Returns:

wx.Font


GetHelp()

Returns the help string associated with the menu item.


Returns:

string


GetId()

Returns the menu item identifier.


Returns:

int


GetItemLabel()

Returns the text associated with the menu item including any accelerator characters that were passed to the constructor or SetItemLabel.


Returns:

string


GetItemLabelText()

Returns the text associated with the menu item, without any accelerator characters.


Returns:

string


GetKind()

Returns the item kind, one of wx.ITEM_SEPARATOR, wx.ITEM_NORMAL, wx.ITEM_CHECK or wx.ITEM_RADIO.


Returns:

int


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.


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

See also

GetText, GetLabel


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


GetMarginWidth()

Gets the width of the menu item checkmark bitmap (Windows only).


Returns:

int


GetMenu()

Returns the menu this menu item is in, or None if this menu item is not attached.


Returns:

wx.Menu


GetSubMenu()

Returns the submenu associated with the menu item, or None if there isn’t one.


Returns:

wx.Menu


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.


GetTextColour()

Returns the text colour associated with the menu item (Windows only).


Returns:

wx.Colour


IsCheckable()

Returns True if the item is checkable.


Returns:

bool


IsChecked()

Returns True if the item is checked.


Returns:

bool


IsEnabled()

Returns True if the item is enabled.


Returns:

bool


IsOwnerDrawn()
No docstrings available for this method.

IsSeparator()

Returns True if the item is a separator.


Returns:

bool


IsSubMenu()

Returns True if the item is a submenu.


Returns:

bool


ResetOwnerDrawn()
No docstrings available for this method.

SetAccel(accel)

Parameters:


SetBackgroundColour(colour)

Sets the background colour associated with the menu item (Windows only).

Parameters:


SetBitmap(bmp)

Sets the bitmap for the menu item (Windows and GTK+ only). It is equivalent to SetBitmaps (bmp, wx.NullBitmap).

Parameters:


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:


SetCheckable(checkable)

Sets the menu item as checkable.

Parameters:

  • checkable (bool)

SetDisabledBitmap(bmpDisabled)

Parameters:


SetFont(font)

Sets the font associated with the menu item (Windows only).

Parameters:


SetHelp(helpString)

Sets the help string.

Parameters:

  • helpString (string)

SetId(id)

Sets the menu item id.

Parameters:

  • id (int)

SetItemLabel(label)

Sets the label associated with the menu item.

Parameters:

  • label (string)

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)

SetMarginWidth(width)

Sets the width of the menu item checkmark bitmap (Windows only).

Parameters:

  • width (int)

SetMenu(menu)

Sets the parent menu which will contain this menu item.

Parameters:


SetOwnerDrawn(ownerDrawn=True)

Parameters:

  • ownerDrawn (bool)

SetSubMenu(menu)

Sets the submenu of this menu item.

Parameters:


SetText(text)

Sets the text associated with the menu item.

Parameters:

  • text (string)

Warning

This function is deprecated in favour of SetItemLabel.


SetTextColour(colour)

Sets the text colour associated with the menu item (Windows only).

Parameters:


Toggle()
No docstrings available for this method.

Properties

Accel
See GetAccel and SetAccel
BackgroundColour
See GetBackgroundColour and SetBackgroundColour
Bitmap
See GetBitmap and SetBitmap
DisabledBitmap
See GetDisabledBitmap and SetDisabledBitmap
Font
See GetFont and SetFont
Help
See GetHelp and SetHelp
Id
See GetId and SetId
ItemLabel
See GetItemLabel
Kind
See GetKind and SetKind
Label
See GetLabel
MarginWidth
See GetMarginWidth and SetMarginWidth
See GetMenu and SetMenu
See GetSubMenu and SetSubMenu
Text
See GetText and SetText
TextColour
See GetTextColour and SetTextColour