Python
  Home arrow Python arrow Page 6 - 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 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 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


    A Look at wxPython - Some Widgets


    (Page 6 of 6 )

    Now let's add some controls to our window. First, though, let's shift the structure of our application. Instead of throwing everything in the global namespace, let's create a class –- a subclass of wxFrame. While we're add it, how about setting the size of our window?

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, wxID_ANY, 'Title', size = ( 350, 350 ) )

          self.Show ( True )

    application = wxPySimpleApp()

    window = Window()

    application.MainLoop()

    Now we're ready. Let's add a simple button to our window:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, wxID_ANY, 'Title', size = ( 350, 350 ) )

          self.button = wxButton ( self, 100, 'Click' )

          self.Show ( True )

    application = wxPySimpleApp()

    window = Window()

    application.MainLoop()

    Ugh, it takes up the whole window. This can be fixed by putting it in a panel:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, wxID_ANY, 'Title', size = ( 350, 350 )  )

          self.panel = wxPanel ( self, wxID_ANY )

          self.button = wxButton ( self.panel, 100, 'Click' )

          self.Show ( True )

    application = wxPySimpleApp()

    window = Window()

    application.MainLoop()

    That's better. Now let's add a text box:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, wxID_ANY, 'Title', size = ( 350, 350 )  )

          self.panel = wxPanel ( self, wxID_ANY )

          self.button = wxButton ( self.panel, 100, 'Click' )

          self.text = wxTextCtrl ( self.panel, 101, 'Some text.', ( 100, 100 ) )

          self.Show ( True )

    application = wxPySimpleApp()

    window = Window()

    application.MainLoop()

    Now let's make our button do something. I won't get into detail about this, since it's pretty simple to understand:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, wxID_ANY, 'Title', size = ( 350, 350 )  )

          self.panel = wxPanel ( self, wxID_ANY )

          self.button = wxButton ( self.panel, 100, 'Click' )

          self.text = wxTextCtrl ( self.panel, 101, 'Some text.', ( 100, 100 ) )

          EVT_BUTTON ( self.panel, 100, self.click )

          self.Show ( True )

       def click ( self, event ):

          message= wxMessageDialog ( self, 'You clicked the button.', 'Clicked', wxICON_EXCLAMATION )

          message.ShowModal()

          message.Destroy()

    application = wxPySimpleApp()

    window = Window()

    application.MainLoop()

    Wrapping Up

    So far, you've learned a little bit about wxPython. You know how to create two simple dialogs, how to create a simple frame, how to create a menu and how to add two basic controls to a panel. That is all I'll explain in this article, but wxPython is a very large library, so don't think that this is it. Dozens of controls, dialogs and frames can be used in your applications –- way more than I can cover in a single article. However, stay tuned. This is definitely not the end.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 3 hosted by Hostway