Python
  Home arrow Python arrow Page 4 - 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 
VeriSign Whitepapers 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    A Look at wxPython - Creating Menus


    (Page 4 of 6 )

    One of the uses of a status bar is to display details about a certain menu option. Let's create a menu for our window. Our menu bar will contain two categories: “One” and “Two”. They will each have four options: “1”, “2”, “3” and “4” and “A”, “B”, “C” and “D”, respectively. Let's bring our plan to life:

    from wxPython.wx import *

    application = wxPySimpleApp()

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

    window.CreateStatusBar()

    # Create "One" and fill it with the options

    one = wxMenu()

    one.Append ( 100, '1', 'This text will display in the status bar.' )

    one.Append ( 101, '2', 'So will this.' )

    one.Append ( 102, '3', 'Option three.' )

    one.Append ( 103, '4', 'Option four.' )

    one.AppendSeparator()

    one.Append ( 104, '5', 'This is isolated from the rest.' )

    # Create "Two" and fill it with the options

    two = wxMenu()

    two.Append ( 105, 'A', 'A.' )

    two.Append ( 106, 'B', 'B.' )

    two.Append ( 107, 'C', 'C.' )

    two.Append ( 108, 'D', 'D.' )

    two.Append ( 109, 'E', 'E.' )

    # Now, we'll add the menu bar and put in the two categories

    bar = wxMenuBar()

    bar.Append ( one, 'One' )

    bar.Append ( two, 'Two' )

    # Finally, we'll put in the menu bar

    window.SetMenuBar ( bar )

    window.Show ( True )

    application.MainLoop()

    Adding a menu isn't very hard, is it? The only thing I would like to point out here is the numbers you see passed to Append. Each menu option must have its own unique number, or the menu will not function properly.

    If we want to make our menu more complex, we can do so. Execute this code for something more advanced than our last example:

    from wxPython.wx import *

    application = wxPySimpleApp()

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

    window.CreateStatusBar()

    # Create a top-level menu

    parent = wxMenu()

    # Create a child menu that will be added to the parent menu

    child = wxMenu()

    child.Append ( 100, 'Option 1', 'Option 1.' )

    child.Append ( 101, 'Option 2', 'Option 2.' )

    # Add the child menu to the parent menu

    parent.AppendMenu ( 102, '&Child\tShift C', child )

    # Add another menu

    # This menu will contain items that work like radio boxes

    radio = wxMenu()

    radio.Append ( 103, 'First', 'First.', wxITEM_RADIO )

    radio.Append ( 104, 'Second', 'Second.', wxITEM_RADIO )

    # Add yet another menu

    # The options in this menu will behave like checkboxes

    check = wxMenu()

    check.Append ( 105, 'Former', 'Former.', wxITEM_CHECK )

    check.Append ( 106, 'Latter', 'Latter.', wxITEM_CHECK )

    # Create a menu bar

    bar = wxMenuBar()

    bar.Append ( parent, 'Parent' )

    bar.Append ( radio, 'Radio' )

    bar.Append ( check, 'Check' )

    window.SetMenuBar ( bar )

    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 6 hosted by Hostway