0% found this document useful (0 votes)
15 views

IIT-Tutorial Lab Week 11

Uploaded by

liufengyuan2015
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

IIT-Tutorial Lab Week 11

Uploaded by

liufengyuan2015
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UNIVERSITY OF CANBERRA

INTRODUCTION TO INFORMATION TECHNOLOGY (4478/8936)


TUTORIAL WEEK 11 - Semester 1 - 2024

IIT- Tutorial Lab Week 11 – Graphical User Interfaces

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:

End with statement:

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.

In general, programs consist of three components—input, processing, and output. In TUI


programs, input is usually obtained from an input statement or by importing data from a file.
Output is usually given by a print statement or stored in a file. When we convert a TUI program
to a GUI program, we replace input and print statements with Label/Entry pairs. Processing
data and inputting and outputting data to files works much the same in both types of
programs. The primary difference is that the processing in GUI programs is usually triggered
by an event.

Some widgets (short for “window gadgets”) are:

• Button: triggers an event when clicked on with the mouse.


• Label: provides an identity for another widget.
• Entry: accepts input from the user and displays output.
• Listbox: allows user to select from a list of options or to display output.
• Scrollbar: adds scrolling capability to list boxes.

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

You might also like