wxPython defines a few standard command identifiers which may be used by the user code and also are sometimes used by wxPython itself. These reserved identifiers are all in the range between wx.ID_LOWEST and wx.ID_HIGHEST and, accordingly, the user code should avoid defining its own constants in this range.

Those are Stock IDs. They should be used for menus and buttons for common items that the represent so that wx can take care of some cross platform differences for you automatically (especially for wxMac).

Using the stock id will allow for wx to automatically specify the correct text (localized if available) for the item:

wx.Button(panel, wx.ID_COPY) # Note no need to specify the label

See the StockButtons example in the demo and the optimizing for mac article in the wiki for some further info.

ID_FILE-ID_FILE9 are builtin ids for the when you use a wx.FileHistory menu, for opening the most recent items.

The stock IDs can be used anywhere an ID is needed, and in some cases will trigger special or platform specific behavior. For example on wxGTK menu items or buttons with stock IDs will automatically be given an icon from the current theme (if the theme uses icons for menus and buttons) and on Mac menu items with the stock about, exit and preferences IDs will be moved to the application menu.

You can also do things like get stock labels from the stock IDs with wx.GetStockLabel, etc. Or you can let wx do it for you by creating the items with no label and just specify the stock ID.

Question: Is wx.ID_EDIT for a menu or menu item?

Answer: Menus don't use IDs, just menu items.

SpecialIDs (last edited 2010-05-17 18:30:36 by 91)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.