Home arrow Python arrow Page 5 - A Look at wxPython

Events - Python

This article is the first in a series covering wxPython, a library that makes it easy for Python programmers to build graphical user interfaces. It introduces some simple dialogs, explains how to create a simple frame, how to create a menu, and how to add two basic controls to a panel.

  1. A Look at wxPython
  2. The Basics
  3. Creating Windows and Status Bars
  4. Creating Menus
  5. Events
  6. Some Widgets
By: Peyton McCullough
Rating: starstarstarstarstar / 23
June 22, 2005

print this article



What good is a menu when it doesn't do anything besides look pretty? Let's add some real functionality to our menu. As you probably have guessed, wxPython makes this very simple. Let's combine our knowledge of dialogs with our knowledge of menus. We just have to glue it together. Remember those unique numbers we assigned to each menu item? We'll use them below:

from wxPython.wx import *

application = wxPySimpleApp()

window = wxFrame ( None, wxID_ANY, 'Title Here.' )


# You'll see the signifigance of "name" in a second

name = 'John Doe'

# Create a menu

# Nothing new here

menu = wxMenu()

menu.Append ( 100, 'Text Entry', 'Open a text entry dialog.' )

menu.Append ( 101, 'Message', 'Open a message dialog.' )

bar = wxMenuBar()

bar.Append ( menu, 'Options' )

window.SetMenuBar ( bar )

# Now we'll make the menu options do something

# First, we'll define two functions:

def text ( event ):

   global name

   textDialog = wxTextEntryDialog ( window, 'What is your name?', 'Name', name )


   name = textDialog.GetValue()


def message ( event ):

   messageDialog = wxMessageDialog ( window, 'Your name is: ' + name, 'Name', wxICON_INFORMATION | wxOK )



# We will now attach our functions to our menu

EVT_MENU ( window, 100, text )

EVT_MENU ( window, 101, message )

window.Show ( True )


>>> More Python Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: