wx.Menu

Inheritance diagram for 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 method of wx.Menu or wx.MenuBar itself or by using wx.Event.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.

Derived From

Class API

Methods

__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


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


AppendCheckItem(id, item, helpString="")

Adds a checkable item to the end of the menu.

Parameters:

  • id (int)
  • item (string)
  • helpString (string)

Returns:

wx.MenuItem


AppendItem(item)

Appends a wx.MenuItem to the current menu.

Parameters:


Returns:

wx.MenuItem


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


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


AppendSeparator()

Adds a separator to the end of the menu.


Returns:

wx.MenuItem


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


Attach(menubar)

Parameters:


Break()
Inserts a break in a menu, causing the next appended item to appear in a new column.

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.

See also

IsChecked


Delete(id)

Deletes the menu item from the menu.

If the item is a submenu, it will not be deleted. Use DestroyId if you want to delete a submenu.

Parameters:

  • id (int): The menu item identifier.

DeleteItem(item)

Deletes the menu item from the menu.

If the item is a submenu, it will not be deleted. Use DestroyItem if you want to delete a submenu.

Parameters:


Returns:

bool


DestroyId(id)

Deletes the menu item with id id from the menu.

If the item is a submenu, it will be deleted. Use Remove if you want to keep the submenu (for example, to reuse it later).

Parameters:

  • id (int)

Returns:

bool


DestroyItem(item)

Deletes the menu item from the menu.

If the item is a submenu, it will be deleted. Use RemoveItem if you want to keep the submenu (for example, to reuse it later).

Parameters:


Returns:

bool


Detach()
No docstrings available for this method.

Enable(id, enable)

Enables or disables (greys out) a menu item.

Parameters:

  • id (int)
  • enable (bool)

See also

IsEnabled


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.


FindItemById(id)

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

Parameters:

  • id (int)

Returns:

wx.MenuItem


FindItemByPosition(position)

Returns the wx.MenuItem given a position in the menu.

Parameters:

  • position (long)

Returns:

wx.MenuItem


GetEventHandler()
No docstrings available for this method.

GetHelpString(id)

Returns the help string associated with a menu item.

Parameters:

  • id (int): The menu item identifier.

Returns:

string

See also

SetHelpString, Append


GetInvokingWindow()
No docstrings available for this method.

GetLabel(itemid)

Returns a menu item label, including any mnemonics and accelerators.

Parameters:

  • itemid (int)

Returns:

string


GetLabelText(itemid)

Returns a menu item label, without any of the original mnemonics and accelerators.

Parameters:

  • itemid (int)

Returns:

string

See also

GetLabel, SetLabel


GetMenuBar()
No docstrings available for this method.

GetMenuItemCount()

Returns the number of items in the menu.


Returns:

long


GetMenuItems()

Returns the list of items in the menu. wx.MenuItemList is a pseudo-template list class containing wx.MenuItem pointers.


Returns:

wx.MenuItemList


GetParent()
No docstrings available for this method.

GetStyle()
No docstrings available for this 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.

See also

SetTitle


Insert(pos, id, text="", help="", kind=wx.ITEM_NORMAL)

Inserts the given item before the position pos.

Inserting the item at position GetMenuItemCount is the same as appending it.

Parameters:

  • pos (long)
  • id (int)
  • help (string)
  • kind (int)

Returns:

wx.MenuItem

See also

Append, Prepend


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


InsertItem(pos, item)

Inserts the given menu item at the specified position.

Parameters:


Returns:

wx.MenuItem


InsertMenu(pos, id, text, submenu, help="")

Parameters:

  • pos (int)
  • id (int)
  • text (string)
  • submenu (wx.Menu)
  • help (string)

Returns:

wx.MenuItem


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


InsertSeparator(pos)

Inserts a separator at the given position.

Parameters:

  • pos (long)

Returns:

wx.MenuItem


IsAttached()
No docstrings available for this method.

IsChecked(id)

Determines whether a menu item is checked.

Parameters:

  • id (int): The menu item identifier.

Returns:

bool

See also

Check


IsEnabled(id)

Determines whether a menu item is enabled.

Parameters:

  • id (int): The menu item identifier.

Returns:

bool

See also

Enable


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

See also

Append, Insert


PrependCheckItem(id, item, helpString="")

Inserts a checkable item at position 0.

Parameters:

  • id (int)
  • item (string)
  • helpString (string)

Returns:

wx.MenuItem


PrependItem(item)

Prepends a menu item at position 0.

Parameters:


Returns:

wx.MenuItem


PrependMenu(id, text, submenu, help="")

Parameters:

  • id (int)
  • text (string)
  • submenu (wx.Menu)
  • help (string)

Returns:

wx.MenuItem


PrependRadioItem(id, item, helpString="")

Inserts a radio item at position 0.

Parameters:

  • id (int)
  • item (string)
  • helpString (string)

Returns:

wx.MenuItem


PrependSeparator()

Inserts a separator at position 0.


Returns:

wx.MenuItem


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


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:


Returns:

wx.MenuItem


SetEventHandler(handler)

Parameters:


SetHelpString(id, helpString)

Sets an item’s help string.

Parameters:

  • id (int): The menu item identifier.
  • helpString (string): The help string to set.

See also

GetHelpString


SetInvokingWindow(win)

Parameters:


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.

See also

Append, GetLabel


SetParent(parent)

Parameters:


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.

See also

GetTitle


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:


Properties

EventHandler
See GetEventHandler and SetEventHandler
HelpString
See GetHelpString and SetHelpString
InvokingWindow
See GetInvokingWindow and SetInvokingWindow
See GetMenuBar
See GetMenuItemCount
See GetMenuItems
Parent
See GetParent and SetParent
Style
See GetStyle
Title
See GetTitle and SetTitle