wxPython

4.2.5 · active · verified Thu Apr 16

wxPython is a cross-platform GUI toolkit for Python, providing a native look and feel on Windows, macOS, and Linux by wrapping the wxWidgets C++ library. The current version (4.x, "Phoenix") is a re-implementation focused on improved speed, maintainability, and extensibility. It is actively maintained with regular releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart creates a basic wxPython application with a main window, a static text label, and a button. Clicking the button displays a message box. The `wx.App(False)` initialization prevents stdout/stderr redirection, and `app.MainLoop()` starts the event processing.

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MyFrame, self).__init__(parent, title=title, size=(300, 200))
        panel = wx.Panel(self)
        text = wx.StaticText(panel, label="Hello, wxPython!", pos=(80, 50))
        button = wx.Button(panel, label="Click Me", pos=(80, 100))
        button.Bind(wx.EVT_BUTTON, self.on_click)
        self.Show()

    def on_click(self, event):
        wx.MessageBox("Button clicked!", "Info", wx.OK | wx.ICON_INFORMATION)

if __name__ == '__main__':
    app = wx.App(False) # False to not redirect stdout/stderr
    frame = MyFrame(None, "Simple wxPython App")
    app.MainLoop()

view raw JSON →