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

Lecture38 Screen

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

Lecture38 Screen

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

LECTURE 38

GUIS WITH TKINTER 2


MCS 260 Fall 2020
David Dumas

/
REMINDERS
Quiz 13 available
TA of ce hours (open to all) replace discussions on
Tue Nov 24. These use different zoom links—see
announcement on course home page.

/
GOAL
Build a tkinter GUI application to encode text by
rotating each letter forward in the alphabet by a xed
number of places.

/
SUBCLASSING TK
A good way to make GUI applications is to subclass
tkinter.Tk and put GUI setup code in __init__.
Then, application data can be stored as class attributes.
Commands and other callbacks can be methods.

/
ROWSPAN AND COLUMNSPAN
These options for .grid of a widget make it span
multiple columns or rows in the layout.

/
TKINTER VARIABLES
tkinter offers mutable variable classes designed to
work with widgets:
tkinter.StringVar — mutable string
tkinter.DoubleVar — mutable oat
tkinter.IntVar — mutable integer
All use .set(val) to set, .get() to get. They
automatically notify widgets that use them of changes.

/
VARIABLE CHANGE CALLBACKS
tkinter variables let us register a function to be
called whenver the value changes:
tkvar.trace_add("write",callback)
The function callback is called with three arguments
(internal name, internal index, operation). Usually you
want to ignore all of these arguments.

/
WINDOW TITLE
Tk.title(s) sets the window title (in title bar).

/
REFERENCES
Of cial tkinter documentation
The Tk docs tutorial demonstrates lots of features, and shows Python code for all its
examples.
Unof cial reference manual by John Shipman

REVISION HISTORY
2020-11-19 Initial publication

You might also like