MCS 260 Fall 2021
Emily Dumas
Build a more interesting tkinter
GUI application.
We'll make a password generator.
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.
These options for .grid
of a widget make it span multiple columns or rows in the layout.
tkinter
offers mutable variable classes designed to work with widgets:
tkinter.StringVar
— mutable stringtkinter.DoubleVar
— mutable floattkinter.IntVar
— mutable integerAll use .set(val)
to set, .get()
to get. They automatically notify widgets that use them of changes.
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.