MONT 105S, Spring 2009

Home | | Course Schedule | | Assignments | | Lecture Notes

Laboratory 9
Due at the end of today's class

A Graphical User Interface
In this lab you will create a Graphical user interface (GUI). Your GUI will look like this on a Mac (it will look somewhat different on the PC):

When the user enters their name, clicks on one of the radio buttons and then hits the submit button, the program will respond by printing the appropriate message in the text box.

For example, if the user enters "Theo" as their name, and clicks on the "Red Sox" button, the text box will say:

Hello, Theo!
I see you like the Red Sox.
You must be from Boston.

If the user enters "George" and clicks on the "Yankees" button, the text box will say:

Hello, George!
I see you like the Yankees.
You must be from New York.

Creating the GUI.
Step 1: Create the root window and the frame.
First, perform the following steps to create the window and the frame:

The following code will accomplish the above tasks:
from Tkinter import *
root = Tk( )
root.title("Baseball")
root.geometry("500x300")
app = Frame(root)
app.grid( )

Step 2. Create the GUI elements.
Creat the following GUI elements:

Finally you should set the event loop going with the command:
root.mainloop( )

Step 3. Write the update_message( ) function.
Write the update_message( ) function definition at the beginning of your file, just after you import the Tkinter library:

from Tkinter import *

def update_message( ):
#Rest of update_message goes here.

Your function should do the following:

Program skeleton
You may use the following program skeleton for your code:

#Your program prologue goes here.

from Tkinter import *

def update_message( ):
#Your definition of the update_message( ) function goes here.

root = Tk( )
root.title("Baseball")
root.geometry("500x300")
app = Frame(root)
app.grid( )

#Create your GUI elements (Widgets) here.

root.mainloop( )

What To Turn In.

Reminder.

Be sure to save a copy of each program on your P:\ drive.