Python
  Home arrow Python arrow Page 5 - A Look at wxPython
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

A Look at wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2005-06-22

    Table of Contents:
  • A Look at wxPython
  • The Basics
  • Creating Windows and Status Bars
  • Creating Menus
  • Events
  • Some Widgets

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    A Look at wxPython - Events


    (Page 5 of 6 )

    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.' )

    window.CreateStatusBar()

    # 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 )

       textDialog.ShowModal()

       name = textDialog.GetValue()

       textDialog.Destroy()

    def message ( event ):

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

       messageDialog.ShowModal()

       messageDialog.Destroy()

    # We will now attach our functions to our menu

    EVT_MENU ( window, 100, text )

    EVT_MENU ( window, 101, message )

    window.Show ( True )

    application.MainLoop()

    More Python Articles
    More By Peyton McCullough


       · Thanks for the good intro, Readers should be sure to check out the 'demo'...
       · Nice basic intro, but there is one major issue. For the last few releases, the...
       · Peyton,Great Introduction for Newbies. You have a knack for being...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway