Wednesday, September 12, 2012

wxPYTHON CHOICE LIST DIALOG





REVISED:  REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython choice list dialog box.

I.  wxPYTHON CHOICE LIST DIALOG BOX

When the program starts the choice list dialog box is displayed. When the user selects a color and clicks OK the "choice list dialog box" is destroyed and the users color selection is printed on the open Python Shell window. When the user clicks Cancel, the "choice list dialog box" is destroyed and the Python Shell window remains open.

II.  wxPYTHON EXAMPLE PROGRAM

Start the Python 2.7.3 interpreter shell by "double left mouse clicking" the Python icon on your desktop. When the "Python Shell" window opens  select "File", then select "New Window". In the "New Window" type the following code.  Use four spaces, columns, for each indent.

import wx

if __name__=='__main__':

# Creates application object named app
        app=wx.PySimpleApp()

# Python list named colorList, first color is 0, second color is 1; etc.
        colorList=['blue', 'green', 'orange', 'purple', 'red',   'violet', 'yellow']

# Creates list dialog box object named color
# Four parameters:
# 1. Parent name is None
# 2. User prompt, is "What is your lucky color?"
# 3. List dialog box title, is "LUCKY COLORS"
# 4. Python list is named colorList
        color=wx.SingleChoiceDialog(None, "What is your lucky color?", "LUCKY COLORS", colorList)

# If OK is clicked, uses string variable %s to print their lucky color on Python Shell window
        if color.ShowModal()==wx.ID_OK:
                print "Your lucky color is %s\n" % color.GetStringSelection()

# Destroys list dialog box object named color
        color.Destroy()

From the "New Window", do a "File Save As" and save the above Python program, using the file name brightListDialog.py to the same path which your computer used to download Python 2.7.3. For example, I saved my brightListDialog.py  file  to my Python27 folder using the following path:

C:\Python27\brightListDialog.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" in the top left corner will open.

The comments which start with  a hash, #, sign explain how this wxPython program works.

Some of the underscores are double underscores; e.g., __init__,  __name__, and __main__  all have double underscores before and after them.

In this tutorial, you have learned how to create a wxPython choice list dialog box.

Elcric Otto Circle



-->



-->



-->





 







How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




No comments:

Post a Comment