Python
  Home arrow Python arrow Dialogs in wxPython
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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

Dialogs in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2005-08-01

    Table of Contents:
  • Dialogs in wxPython
  • wxScrolledMessageDialog
  • wxProgressDialog
  • ImageDialog
  • wxDirDialog
  • wxFileDialog

  • 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

    Dialogs in wxPython
    (Page 1 of 6 )

    You are probably already familiar with a few dialogs that can be used in your wxPython applications. Of course, wxPython contains many more dialogs, ranging in complexity from very simple to pretty advanced and covering a variety of topics, from text selection to color selection. In this article, we'll take a look at more of wxPython's dialogs – what they are for and how they are placed in an application.

    wxSingleChoiceDialog

    Instead of using a wxListBox to gather input from a user, you can use the wxSingleChoiceDialog. Upon calling it, a dialog is displayed to the user with a list of items that the user can select. The user may only select one item on the list. At the bottom of the dialog, there is an “OK” button and a “Cancel” button. Let's create a simple application with the dialog:

    from wxPython.wx import *

    from wxPython.lib.dialogs import *

    application = wxPySimpleApp()

    # Create a list of choices

    choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

    # Create the dialog

    dialog = wxSingleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )

    # Show the dialog

    dialog.ShowModal()

    # Destroy the dialog

    dialog.Destroy()

    Of course, to make our dialog of any use, we'll have to catch the user's selection and perhaps react to the user pressing the “Cancel” button:

    from wxPython.wx import *

    application = wxPySimpleApp()

    choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

    dialog = wxSingleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )

    # The user pressed the "OK" button in the dialog

    if dialog.ShowModal() == wxID_OK:

       print 'Position of selection:', dialog.GetSelection()

       print 'Selection:', dialog.GetStringSelection()

    # The user exited the dialog without pressing the "OK" button

    else:

       print 'You did not select anything.'

    dialog.Destroy()

    If we want to give the user the option of selecting multiple items by pressing the shift key while clicking a selection or holding down the mouse and moving the cursor down, we can do so with wxMultiChoiceDialog:

    from wxPython.wx import *

    application = wxPySimpleApp()

    choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

    dialog = wxMultiChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )

    # The user pressed the "OK" button in the dialog

    if dialog.ShowModal() == wxID_OK:

       selected = dialog.GetSelections()

       for selection in selected:

          print str ( selection ) + ': ' + choices [ selection ]

    # The user exited the dialog without pressing the "OK" button

    else:

       print 'You did not select anything.'

    dialog.Destroy()

    More Python Articles
    More By Peyton McCullough


       · goog topic, but it doesn't work well :Traceback (most recent call last): File...
       · We returned to the original article and it seemed that a line of code was missed...
       · Vous avez écrit :dialog = wxScrolledMessageDialog ( self, text, 'Fairy Tale'...
     

       

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