Introduction to wxPython

Minimal Application

import wx
class Minimal(wx.App):
    def OnInit(self):
        main_window = wx.Frame(None, -1, "")
        return 1
if __name__ == "__main__":
    app = Minimal(0)

Types of Windows

  • wx.Frame
  • wx.Panel
  • wx.Dialog
  • Other windows usually subclass or use one of these

Building up the GUI

  • Application creates the top level window
  • Top level window (wx.Frame) is the parent for:
    • menu bar, status bar, panels, dialogs
  • Panels and dialogs contain:
    • buttons, text boxes, drop downs, etc

Building Menus

  • Optionally, create new event IDs
  • Create a menu bar
  • Create a menu
  • Append menu items to the menu
  • Append the menu to the menu bar
  • Set the frame’s menu bar to the one created
  • Bind the menu entry ID to an event handling method

Types of Widgets

  • Button - wx.Button
  • Toggle Button - wx.ToggleButton
  • Text Box - wx.TextCtrl
  • Static Text - wx.StaticText
  • Drop Down Menu - wx.Choice, wx.ComboBox
  • Selection List - wx.ListBox
  • Radio button - wx.RadioButton, wx.RadioBox
  • Checkbox - wx.CheckBox
  • Slider - wx.Slider

Adding Widgets

As with the panel, parent widgets to the window containing them. In this case, the new panel.

self.btn = wx.Button(self.panel, -1, "My Button!")
self.btn.Bind(wx.EVT_BUTTON, self.OnQuit)


Sizers control the placement of widgets, allowing them to grow and shrink depending on font sizes, languages, and window sizes.

  • Sizers place widgets, they do not parent them
  • Sizers lay items out horizontally, vertically, in grids, etc
  • Sizers can be added to other sizers
  • Sizers are the best and worst feature of wxWidgets/wxPython
  • Using wxGlade can make using sizers easy, with preparation