Python
  Home arrow Python arrow Page 2 - Checkboxes and Radio Buttons in wxPython
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

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


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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek