wxPython Classes Cheat Sheet
A wikipage to help you write scripts which was generated by a script attatched to the wikipage.
NB: Think of this page as a collection of shortcuts to the docs. It is not comprehensive in any way. There are many more classes in the wx library than listed here, and most classes have many more methods. I only add to this page as I encounter new features that I need in my projects, and I've just discovered PySide. - Anthony.
Contents:
wx.App:
wx.Window:
wx.Sizer:
wx.Control:
Control, Button, ToggleButton, RadioButton, CheckBox, RadioBox, StaticBitmap, StaticPicture, StaticText, TextCtrl, Gauge, RichTextCtrl, ListCtrl, TreeCtrl
wx.ItemContainer(Control):
wx.Event:
EvtHandler, Event, ActivateEvent, CloseEvent, CommandEvent, MouseEvent, MenuEvent, IdleEvent, PaintEvent, ShowEvent
wx.Font:
wx.Image:
wx.DC:
App classes
The gui itself. Controls the event loop.
Notes:- Top-level windows can not be created before the app object.
Over-ride OnInit. Don't know why it's undocumented.
OnInit should return a boolean value. (And don't forget to call Frame.Show(True).)
Call MainLoop
__init__
(redirect=False, filename=None, clearSigInt=True, useBestVisual=False)
- Execute the main GUI event loop.
When you don't feel like over-riding Init.
Notes:Make the app before the frames!
Window classes
Abstract parent of all visible elements.
Events: EVT_WINDOW_CREATE, EVT_WINDOW_DESTROY, EVT_SIZE, EVT_CLOSE
__init__
(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.PanelNameStr)
Styles: wx.BORDER_SIMPLE, wx.BORDER_DOUBLE, wx.BORDER_SUNKEN, wx.BORDER_RAISED, wx.BORDER_STATIC, wx.BORDER_THEME, wx.BORDER_NONE, wx.TRANSPARENT_WINDOW, wx.TAB_TRAVERSAL, wx.WANTS_CHARS, wx.VSCROLL, wx.HSCROLL, wx.CLIP_CHILDREN, wx.FULL_REPAINT_ON_RESIZE
- Gets the dimensions of the string as it would be drawn on the window with the currently selected font.
- Invokes the constraint-based layout algorith or the sizer-based algorithm for this window.
If autoLayout is True Layout is called every time there is an EVT_SIZE event for the window.
- Shows or hides the window.
Notes:
If you add a window (i.e. a control or panel) without using a sizer it's size info will be ignored and it will fill the frame.
__init__
(parent, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name=wx.FrameNameStr)
Styles: wx.STAY_ON_TOP, wx.SYSTEM_MENU, wx.RESIZE_BORDER, wx.FRAME_TOOL_WINDOW, wx.FRAME_NO_TASKBAR, wx.FRAME_FLOAT_ON_PARENT
note1: Setting the parent to None makes the frame a 'top level' window.
CreateStatusBar
(number=1, style=wx.ST_SIZEGRIP|wx.FULLREPAINT_ON_RESIZE, id=0, name="statusBar")
note1: A multi-field status bar can be created by providing a number > 1
CreateToolBar
(style=wx.NO_BORDER|wx.TB_HORIZONTAL, id=-1, name="toolBar")
note1: According to the docs, SetAutoLayout is called implicitly.
note1: number: The status field.
__init__
(parent, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL | wx.NO_BORDER, name=wx.PanelNameStr)
Styles: See Window
__init__
(parent, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, name=wx.DialogNameStr)
When you want some combination of Yes/No/Ok/Cancel.
Notes:Returns one of: wx.ID_OK, wx.ID_CANCEL, wx.ID_YES, or wx.ID_NO
Alternative: wx.MessageBox(message, caption="Message", style=wx.OK)
__init__
(parent, message, caption="Message Box", style=wx.OK | wx.Cancel, pos=wx.DefaultPosition)
Styles: wx.CANCEL, wx.NO_DEFAULT, wx.OK, wx.YES_DEFAULT, wx.YES_NO, wx.ICON_ERROR, wx.ICON_EXCLAMATION, wx.ICON_HAND, wx.ICON_INFORMATION, wx.ICON_QUESTION
__init__
(title, message, maximum=100, parent=None, style=wx.PD_AUTO_HIDE|wx.PD_APP_MODAL)
Styles: wx.PD_APP_MODAL, wx.PD_AUTO_HIDE, wx.PD_SMOOTH, wx.PD_CAN_ABORD, wx.PD_CAN_SKIP, wx.PD_ELAPSED_TIME, wx.PD_ESTIMATED_TIME, wx.PD_REMAINING_TIME
note1: Returns (keep_going, skip)
note1: Returns (keep_going, skip)
Sizer classes
The abstract parent wxclass for sizers.
note1: 'item' is a window, a sizer, or the dimensions of a spacer.
note2: 'proprotion' is the share of space taken if the item is set to EXPAND.
note3: 'border' is just the border width
note4: border flags: wx.TOP/BOTTOM/LEFT/RIGHT/ALL
note5: resize flags: wx.EXPAND(or GROW)/SHAPED. 'shaped' means 'expand with aspect ratio'
note6: align flags: wx.ALIGN_CENTER/ALIGN_LEFT/ALIGN_RIGHT/ALIGN_TOP/ALIGN_BOTTOM/ALIGN_CENTER_VERTICAL/ALIGN_CENTER_HORIZONTAL
- Resizes the window to the sizer's minimal size.
Simple rows or columns.
note1: orient may be wx.HORIZONTAL or wx.VERTICAL
A BoxSizer with a static box around the sizer.
Notes:The sizer owns the StaticBox.
Think calculator. Number pad. Ect.
Notes:- The width of all fields is the width of the widest child.
The height of all fields is the height of the tallest child.
note1: If rows or cols is 0, it will be calculated dynamically.
Think table.
Notes:Not all rows or columns are necessarily the same height or width.
- Specifies that column idx (starting from 0) should be grown if there is extra space available to the sizer. If all proportions are 0, then all columns are resized equally (instead of not being resized at all).
- As above.
Table with cells that can span multiple rows or cols.
note1: to place a widget in the second row, first column and have it take up three rows and two columns, you would use the call Add(widget, (1, 0), (3, 2)).
Control classes
Base class for all controls
__init__
(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.ControlNameStr)
- Simulates the effect of the user issuing a command to the item.
wx.Window's GetLabel method will return the & characters.
Events: wx.EVT_BUTTON
__init__
(parent, id=-1, label=EmptyString, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.ButtonNameStr)
Styles: wx.BU_LEFT, wx.BU_TOP, wx.BU_RIGHT, wx.BU_BOTTOM, wx.BU_EXACTFICT
note1: Preferred creation method is to use a standard ID and an empty label. See the list of Stock IDs at wxWidgets.
Events: wx.EVT_TOGGLEBUTTON
Notes:"Value" refers to the boolean value of the button's state.
Events: wx.EVT_CHECKBOX
__init__
(parent, id=-1, label="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.CheckBoxNameStr)
Styles: wx.ALIGN_RIGHT
Meant for the display of small icons.
Notes:Under Windows 9x the size of bitmap is limited to 64*64 pixels
__init__
(parent, id=-1, bitmap=wx.NullBitmap, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.StaticBitmapNameStr)
Notes:
Inherits GetLabel and SetLabel from Window.
__init__
(parent, id=-1, label=EmptyString, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=StaticTextNameStr)
Uses \n to seperate lines. Never use the indices returned by a multiline wx.TextCtrl as indices into the string it contains, but only as arguments to be passed back to the other wx.TextCtrl methods.
Events: wx.EVT_TEXT, wx.EVT_CHAR, wx.EVT_TEXT_ENTER, wx.EVT_TEXT_URL, wx.EVT_TEXT_MAXLEN
__init__
(parent, id=-1, value="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, validator=DefaultValidator, name=wx.TextCtrlNameStr)
Styles: wx.TE_PROCESS_ENTER, wx.TE_PROCESS_TAB, wx.TE_MULTILINE, wx.TE_PASSWORD, wx.TE_READONLY, wx.TE_LEFT, wx.TE_CENTRE, wx.TE_RIGHT, wx.TE_DONTWRAP, wx.TE_BESTWRAP
- Limit the number of input characters.
note1: If multiline, string uses \n, not \r\n.
A progress bar.
__init__
(parent, id=-1, range=100, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.GA_HORIZONTAL, validator=wx.DefaultValidator, name=wx.GaugeNameStr)
Styles: wx.GA_HORIZONTAL, wx.GA_VERTICAL
- Each call pulses it a bit. See wx.Timer
ItemContainer(Control) classes
Abstract parent of ListBox, CheckListBox, Choice, and ComboBox
Returns integer or wx.NOT_FOUND. You kept a reference to the list, right?
- List? What list?
A pulldown menu.
Events: wx.EVT_CHOICE
__init__
(parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name=wx.ChoiceNameStr)
note1: I don't know why there is no default value (-1) for id.
- Returns the last selected value.
- Returns the currently selected option in the drop-down.
An ItemContainer.
Events: wx.EVT_LISTBOX(id, func) / wx.wxEVT_COMMAND_LISTBOX_SELECTED, wx.EVT_LISTBOX_DCLICK(id, func) / wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
__init__
(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name=wx.ListBoxNameStr)
Styles: wx.LB_SINGLE, wx.LB_MULTIPLE, wx.LB_EXTENDED, wx.LB_HSCROLL, wx.LB_ALWAYS_SB, wx.LB_NEEDED_LB, wx.LB_SORT
- Returns list of integers
- Clears and sets strings
Event classes
All windows (and therefore controls) are event handlers.
Notes:When events are received, wx.EvtHandler invokes the method listed in the event table using itself as the object.
note1: event: One of the wx.EVT_* objects that specifies the type of event to bind.
note2: handler: the function to call when the event is delivered to self.
note3: source: the object (control) that generated the event.
Abstract parent of all events.
Sent when top-level window or entire application activated or deactivated.
Events: wx.EVT_ACTIVATE, wx.EVT_ACTIVATE_APP
Notes:Don't confuse this with wx.FocusEvent.
Calling event.Skip() when handling is a good idea.
- Returns true when activated.
Font classes
note1: See constructor for family and weight constants
Image classes
Can be loaded from file but not drawn to a wx.DC
Notes:Use ConvertToBitmap method to draw to a wx.DC
note1: name is the filename
note2: index is for multipage gif, ico, or tifs
note1: The docs don't show it, but 'depth' is optional
- Returns a string of the RGB bytes of the image.
note1: Returns a new wx.Image
DC classes
This page was created by AnthonyGlaser.
Please don't edit this page directly. Instead, download cheat_sheet.xml, models.py , and xml_parser.py. Modify cheat_sheet.xml and run the function write_sheet in xml_parser.py. Upload the output and attach any changed files.
Or just stay tuned for updates.