wxPython Window

wxPython is a cross-platform GUI toolkit for Python. It provides native looks and performance on Windows, macOS, and Linux.

Creating a wxPython Window

To create a window in wxPython, you instantiate a wx.App object and create a wx.Frame:

import wx

app = wx.App()
frame = wx.Frame(None, title="Hello wxPython", size=(400, 300))
frame.Show(True)
app.MainLoop()

Object-Oriented wxPython Window

The standard way to build applications with wxPython is by subclassing wx.Frame:

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MyFrame, self).__init__(parent, title=title, size=(450, 320))
        self.Centre()

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, title="wxPython Window Example")
    frame.Show()
    app.MainLoop()
Back ⚡ Practice with PyChallengeNext