Python
  Home arrow Python arrow Page 2 - Checkboxes and Radio Buttons in wxPyth...
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 
 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

Checkboxes and Radio Buttons in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    2005-08-22

    Table of Contents:
  • Checkboxes and Radio Buttons in wxPython
  • wxCheckListBox
  • wxRadioButton
  • wxRadioBox

  • 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

    Checkboxes and Radio Buttons in wxPython - wxCheckListBox


    (Page 2 of 4 )

    The wxCheckListBox is a combination of wxCheckBox and wxListBox. It is basically a list of checkboxes that users can click. It's useful if you have a large amount of checkboxes. Let's create an application that shows off wxCheckListBox's features:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Dinner', size = ( 300, 300 ) )

          # Create a status bar

          self.CreateStatusBar()

          # Create a panel

          self.panel = wxPanel ( self, -1 )

          # Create a label

          self.label = wxStaticText ( self.panel, -1, 'Configure your dinner:' )

          # Define a list of items to place in the wxCheckListBox

          self.dinner = [ 'Ravioli', 'Apple Pie', 'Dr. Pepper', 'Soup', 'Salad', 'Ham Sandwich', 'Pizza', \

                          'Macaroni and Cheese', 'Carrot Cake', 'Spinach', 'Potato Salad ( Southern Style )' ]

          # Create a wxCheckListBox

          self.box = wxCheckListBox ( self.panel, 100, size = ( 150, 100 ), choices = self.dinner, style = wxLB_HSCROLL )

          # Hook up an event handling method

          EVT_CHECKLISTBOX ( self.panel, 100, self.clickHandler )

          # Create a button

          self.button = wxButton ( self.panel, 200, 'Prepare' )

          # Hook up an event handling method

          EVT_BUTTON ( self.panel, 200, self.buttonHandler )

          # Create two sizers to make everything pretty

          # The usual

          self.vertical = wxBoxSizer ( wxVERTICAL )

          self.vertical.Add ( ( 0, 0 ), 1 )

          self.vertical.Add ( self.label, 0, wxALIGN_CENTER )

          self.vertical.Add ( ( 5, 5 ), 0 )

          self.vertical.Add ( self.box, 0, wxALIGN_CENTER )

          self.vertical.Add ( ( 5, 5 ), 0 )

          self.vertical.Add ( self.button, 0, wxALIGN_CENTER )

          self.vertical.Add ( ( 0, 0 ), 1 )

          self.horizontal = wxBoxSizer ( wxHORIZONTAL )

          self.horizontal.Add ( ( 0, 0 ), 1 )

          self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

          self.horizontal.Add ( ( 0, 0 ), 1 )

          # Attach the sizer

          self.panel.SetSizerAndFit ( self.horizontal )

          self.Show ( True )

       # This method is called when an item is clicked

       def clickHandler ( self, event ):

          if self.box.IsChecked ( event.GetSelection() ):

             message = ' will be prepared.'

          else:

             message = ' will not be prepared.'

          # Update the status bar of the window

          self.SetStatusText ( self.box.GetString ( event.GetSelection() ) + message )

       # This method will be called when the button is clicked

       def buttonHandler ( self, event ):

          message = 'The following items have been prepared:'

          # Check to see what has been selected and what has not

          x = 0

          for choice in self.dinner:

             if self.box.IsChecked ( x ):

                message = message + '\n' + choice

             x = x + 1

          # Display a dialog

          dialog = wxMessageDialog ( self, message, 'Your dinner is ready.', style = wxOK )

          dialog.ShowModal()

          dialog.Destroy()

    application = wxPySimpleApp()

    Window()

    application.MainLoop()

    More Python Articles
    More By Peyton McCullough


       · Too complicated
       · I would not label it as complicated at all, and using .NET would mean losing...
     

       

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