Python
  Home arrow Python arrow Page 3 - A Close Look at wxPython Controls
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 Close Look at wxPython Controls
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-07-06

    Table of Contents:
  • A Close Look at wxPython Controls
  • wxComboBox and wxListBox
  • wxListBox is versatile
  • wxTextCtrl
  • Password text boxes, read-only text boxes

  • 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 Close Look at wxPython Controls - wxListBox is versatile


    (Page 3 of 5 )

    The wxListBox control supports multiple selections. We must handle this differently as well:

    from wxPython.wx import *

    class OurFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'wxPython' )

          self.panel = wxPanel ( self, -1 )

          self.list = wxListBox ( self.panel, -1, choices = [ '1', '2', '3', '4' ], style = wxLB_MULTIPLE )

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

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

          self.sizer = wxBoxSizer ( wxVERTICAL )

          self.sizer.Add ( self.list, 0 )

          self.sizer.Add ( self.button, 0 )

          self.panel.SetSizerAndFit ( self.sizer )

          self.Show ( True )

       def click ( self, event ):

          selections = self.list.GetSelections()

          if len ( selections ) > 1:

             for selection in selections:

                print 'Multiple Selected:', self.list.GetString ( selection )

          else:

             print 'Single Selected:', self.list.GetString ( selections [ 0 ] )

    application = wxPySimpleApp()

    window = OurFrame()

    application.MainLoop()

    We can insert a whole list of items rather than one at a time, and we can also reset the list entirely, without using Clear:

    from wxPython.wx import *

    class OurFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'wxPython' )

          self.panel = wxPanel ( self, -1 )

          self.list = wxListBox ( self.panel, -1, choices = [ '1', '2', '3', '4' ] )

          # Reset it

          self.list.Set ( [ 'Choice 1', 'Choice 2', 'Choice 3', 'Choice 4' ] )

          # Add some more items

          self.list.InsertItems ( [ 'Choice 5', 'Choice 6', 'Choice 7', 'Choice 8', 'Choice 9', 'Choice 10' ], 4 )

          self.lilst.InsertItems ( [ 'Choice 0' ], 0 )

          self.sizer = wxBoxSizer ( wxVERTICAL )

          self.sizer.Add ( self.list, 0 )

          self.panel.SetSizerAndFit ( self.sizer )

          self.Show ( True )

    application = wxPySimpleApp()

    window = OurFrame()

    application.MainLoop()

    Finally, let's look at some events:

    from wxPython.wx import *

    class OurFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'wxPython' )

          self.panel = wxPanel ( self, -1 )

          self.list = wxListBox ( self.panel, 100, choices = [ 'One', 'Two', 'Three', 'Four' ] )

          self.combo = wxComboBox ( self.panel, 200, choices = [ 'Red', 'Blue', 'Green', 'Pink' ] )

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

          EVT_LISTBOX_DCLICK ( self.panel, 100, self.listDouble )

          EVT_COMBOBOX ( self.panel, 200, self.click )

          EVT_TEXT_ENTER ( self.panel, 200, self.comboEnter )

          EVT_TEXT ( self.panel, 200, self.comboText )

          self.sizer = wxBoxSizer ( wxVERTICAL )

          self.sizer.Add ( self.list, 0 )

          self.sizer.Add ( self.combo, 0 )

          self.panel.SetSizerAndFit ( self.sizer )

          self.Show ( True )

       def click ( self, event ):

          print 'Single click.'

       def listDouble ( self, event ):

          print 'Double click.'

       def comboEnter ( self, event ):

          print 'You pressed enter in the wxComboBox.'

       def comboText ( self, event ):

          print 'You changed the text in the wxComboBox.'

    application = wxPySimpleApp()

    window = OurFrame()

    application.MainLoop()

    More Python Articles
    More By Peyton McCullough


     

       

    PYTHON ARTICLES

    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - 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

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT