IIT-Tutorial Lab Week 11
IIT-Tutorial Lab Week 11
Introduction
In this week’s tutorial, we will start with GUIs. This is an important preparation work for your
Assignment number 3.
Widgets are the components of a graphical user interface (GUI). Widgets are objects, and
their classes are defined in a module named tkinter (pronounced t-k-inter; stands for TK
interface). Each GUI program will begin with the two statements:
The first statement imports the tkinter module and the second statement creates an instance
of the TK class and gives it the name window. The mainloop function acts like an infinite loop
that keeps looking for events until you close the window by clicking on its Close button.
Geometry managers are tools used to place widgets on the screen. A grid is an imaginary
rectangle containing horizontal and vertical lines that subdivide it into rectangles called cells.
A graphical interface is created by placing widgets into a grid. A widget can be inserted into
an individual cell or can span a consecutive sequence of rows or columns. Each row and
column expand to fit the largest widget in that row and column.
Page 1|2
UNIVERSITY OF CANBERRA
INTRODUCTION TO INFORMATION TECHNOLOGY (4478/8936)
TUTORIAL WEEK 11 - Semester 1 - 2024
The captions for Button and Label widgets are specified by text attributes in their
constructors. Code can be used to retrieve text from and put text into an Entry widget. First
an object (call it x) of type StringVar is declared and assigned to the Entry widget’s textvariable
attribute. Then x’s get and set methods can be used to retrieve text from and put text into
the Entry widget. Although text can be typed into ordinary Entry widgets, text only can be
placed into ReadOnly Entry widgets via the set method. An Entry widget is specified as
ReadOnly by inserting state="readonly" into its constructor.
The Challenges
Exercise 1: Calculator. Write a GUI program that allows the user to specify two numbers and
then adds, subtracts, or multiplies them when the user clicks on the appropriate button, see
below for the sample outputs for this program:
Exercise 2: Oceans. Table below contains the names of the five Oceans. Write a program that
displays the Oceans in alphabetical order in a list box as shown by the sample output.
Page 2|2