MONT 105S, Spring 2009
Home | | Course Schedule | | Assignments | | Lecture NotesLaboratory 9
A Graphical User Interface
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:
If the user enters "George" and clicks on the "Yankees" button, the text box will say:
Creating the GUI.
Step 2. Create the GUI elements.
Finally you should set the event loop going with the command:
Step 3. Write the update_message( ) function.
Your function should do the following:
Program skeleton
What To Turn In. Reminder. Be sure to save a copy of
each program on your
Due at the end of today's class
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):
Hello, Theo!
I see you like the Red Sox.
You must be from Boston.
Hello, George!
I see you like the Yankees.
You must be from New York.
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( )
Creat the following GUI elements:
root.mainloop( )
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.
message = "Hello, " + entry_field.get( ) + "!\n"
message = message + "I see you like the " + team.get( ) + ".\n"
"You must be from Boston.\n"
"You must be from New York.\n"
"Please select a team.\n"
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( )