GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask
  • Introduction1 min read
  • Input & Output2 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Python | wxPython module Introduction - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask

Python | wxPython module Introduction

Last Updated : 23 Jul, 2026

wxPython is a cross-platform GUI toolkit that allows Python developers to create desktop applications for Windows, macOS, and Linux using native user interface components. It is built on top of the wxWidgets C++ library.

  • Supports windows, dialogs, menus, toolbars, and other GUI components.
  • Provides layout managers for responsive interfaces.
  • Supports event-driven programming.

Installation

Install wxPython using pip:

pip install wxPython

Verify the installation:

import wx
print(wx.version())

Structure of a wxPython Application

A wxPython application consists of a few core components that work together to create and display a graphical user interface (GUI).

  • wx.App: Initializes the application and manages its lifecycle.
  • wx.Frame: Creates the main application window.
  • wx.Panel: Acts as a container for GUI controls such as buttons, labels, and text boxes.
  • Widgets: User interface elements such as StaticText, Button, CheckBox, and RadioButton that are added to the panel.
  • MainLoop(): Starts the application's event loop and keeps the window responsive until it is closed.
Python
import wx

app = wx.App()
frame = wx.Frame(None, title="My First wxPython App")
panel = wx.Panel(frame)
label = wx.StaticText(panel, label="Hello, wxPython!")
frame.Show()
app.MainLoop()

Note: Every wxPython application begins by creating a wx.App object and ends by calling MainLoop(). Without the event loop, the application window will not remain open or respond to user interactions.

Steps to Create a wxPython Application

  1. Import the wx module.
  2. Create an application object using wx.App().
  3. Create a main window using wx.Frame.
  4. Add a wx.Panel to hold GUI controls.
  5. Add widgets such as labels, buttons, or checkboxes.
  6. Display the window using Show().
  7. Start the event loop using MainLoop().

Example 1: Creating a wxPython Window

The following example creates a basic wxPython application that displays a window containing a text label.

Python
import wx

# Create the application object
app = wx.App()

# Create the main application window
frame = wx.Frame(None, title="wxPython Example", size=(400, 200))

# Create a panel to hold widgets
panel = wx.Panel(frame)

# Create a vertical layout manager
sizer = wx.BoxSizer(wx.VERTICAL)

# Add a text label
label = wx.StaticText(panel, label="GEEKS FOR GEEKS")

# Add the label to the layout manager
sizer.Add(label, 0, wx.ALL | wx.CENTER, 20)

# Apply the layout manager to the panel
panel.SetSizer(sizer)

# Display the window
frame.Show()

# Start the application event loop
app.MainLoop()

Output: 

Explanation:

  • wx.StaticText() displays text on the panel.
  • sizer.Add() adds the label to the layout manager with alignment and spacing.
  • panel.SetSizer() applies the layout manager to the panel.
  • frame.Show() displays the application window.
  • app.MainLoop() starts the event loop and keeps the application responsive until it is closed.

Example 2: Adding a Button 

Buttons allow users to perform an action when they are clicked. In wxPython, button click events can be handled by binding the button to an event handler.

Python
import wx


class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="Button Example", size=(350, 200))

        panel = wx.Panel(self)

        sizer = wx.BoxSizer(wx.VERTICAL)

        button = wx.Button(panel, label="Click Me")
        button.Bind(wx.EVT_BUTTON, self.on_button_click)

        sizer.Add(button, 0, wx.ALL | wx.CENTER, 20)

        panel.SetSizer(sizer)

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


app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()

Output: 

Explanation:

  • wx.Button() creates a button widget.
  • Bind() associates the button click event (wx.EVT_BUTTON) with the on_button_click() method.
  • wx.MessageBox() displays a dialog when the button is clicked.
  • BoxSizer automatically positions the button within the window.

Note: Event binding allows widgets to respond to user interactions, making GUI applications interactive.

Example 3: Adding CheckBoxes

Checkboxes allow users to select multiple independent options. Each checkbox can be checked or unchecked without affecting the others.

Python
import wx

app = wx.App()

frame = wx.Frame(None, title="CheckBox Example", size=(350, 220))

panel = wx.Panel(frame)

sizer = wx.BoxSizer(wx.VERTICAL)

checkbox1 = wx.CheckBox(panel, label="Python")
checkbox2 = wx.CheckBox(panel, label="Java")

sizer.Add(checkbox1, 0, wx.ALL, 10)
sizer.Add(checkbox2, 0, wx.ALL, 10)

panel.SetSizer(sizer)

frame.Show()

app.MainLoop()

Output: 

Explanation:

  • wx.CheckBox() creates a checkbox control.
  • Two independent checkboxes are added to the panel.
  • BoxSizer arranges the checkboxes vertically.
  • Each checkbox can be selected or cleared independently of the other

Note: Use checkboxes when users need to select zero, one, or multiple options.

Example 4: Adding Radio Buttons

Radio buttons allow users to choose only one option from a group of related choices.

Python
import wx

app = wx.App()

frame = wx.Frame(None, title="Radio Button Example", size=(350, 220))

panel = wx.Panel(frame)

sizer = wx.BoxSizer(wx.VERTICAL)

radio1 = wx.RadioButton(panel, label="Python", style=wx.RB_GROUP)
radio2 = wx.RadioButton(panel, label="Java")

sizer.Add(radio1, 0, wx.ALL, 10)
sizer.Add(radio2, 0, wx.ALL, 10)

panel.SetSizer(sizer)

frame.Show()

app.MainLoop()

Output: 

Explanation: 

  • wx.RadioButton() creates a radio button control.
  • The first radio button uses wx.RB_GROUP to start a new radio button group.
  • Only one radio button in the group can be selected at a time.
  • BoxSizer automatically arranges the radio buttons vertically.

Note: Use radio buttons when users must choose exactly one option from a group of mutually exclusive choices.

Common Widgets

WidgetPurpose
StaticTextDisplay text
ButtonPerform actions
TextCtrlAccept input
CheckBoxToggle option
RadioButtonChoose one option
ComboBoxDropdown
ListBoxDisplay list
Comment

Explore

    Python Fundamentals
    • Introduction1 min read
    • Input & Output2 min read
    • Variables4 min read
    • Operators4 min read
    • Keywords2 min read
    • Data Types4 min read
    • Conditional Statements3 min read
    • Loops3 min read
    • Functions4 min read
    Python Data Structures
    • String4 min read
    • List3 min read
    • Tuples3 min read
    • Dictionary3 min read
    • Set2 min read
    • Arrays5 min read
    Advanced Python
    • OOP Concepts3 min read
    • Exception Handling5 min read
    • File Handling4 min read
    • Python Database2 min read
    • MongoDB3 min read
    • MySQL7 min read
    • Packages4 min read
    • Modules3 min read
    • DSA Libraries5 min read
    • Python GUI2 min read
    Data Science with Python
    • Numpy3 min read
    • Pandas4 min read
    • Matplotlib3 min read
    • Seaborn3 min read
    • StatsModel2 min read
    • Model Building6 min read
    • TensorFlow2 min read
    • PyTorch5 min read
    Web Development with Python
    • Flask3 min read
    • Django5 min read
    • Django ORM4 min read
    • Jinja2 Templating5 min read
    • Django Templates5 min read
    • REST API3 min read
    • Build API with DRF4 min read
    Python Practice
    • Quiz1 min read
    • Practice Problems2 min read
    • Interview Q & A15+ min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • AI Engg Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.