REVISED: Sunday, March 3, 2013
In this tutorial, you will learn how to create a wxPython list for user input.
I. wxPYTHON LIST FOR USER INPUT
A wxPython list is used to get input from the user. The list title is shown at the top left of the panel. The question the user is to respond to is show under the list title. The list from which the user selects a response is in the center on the panel. The bottom of the panel has two buttons: OK, and Cancel. If the user clicks Cancel the user selection is not assigned to a variable and the frame is closed. If the user clicks OK the user selection is assigned to a variable and the frame is closed.
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, which is an expansion of the class bright we worked with in the last tutorial. Use four spaces, columns, for each indent.
import wx
class bright(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Bright List', size=(800,400))
panel=wx.Panel(self)
# Creates a list box object named box
box=wx.SingleChoiceDialog(panel, 'Who is burried in Grants Tomb?','QUESTION',['Mickey Mouse', 'Elvis', 'Grant', 'Donald Duck'])
# Stores user selection in variable answer, if user clicks OK
if box.ShowModal()==wx.ID_OK:
answer=box.GetStringSelection()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bright(parent=None,id=-1)
frame.Show()
app.MainLoop()
From the "New Window", do a "File Save As" and save the above Python program, using the file name brightList.py to the same path which your computer used to download Python 2.7.3. For example, I saved my brightList.py
file to my Python27 folder using the following path:
C:\Python27\brightList.py
From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "Bright List" 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.
-->
-->
-->
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