Lecture 40

GUIs with tkinter 3

MCS 260 Fall 2021
David Dumas


Idle is a graphical code development environment (or integrated development environment, IDE) for Python.

It is the officially-supported IDE for Python.

Idle is written in Python using tkinter! (docs, source)

Plan for today

Continue working on the GUI password generator we started in lecture 38.

So far: Built GUI controls.

Remaining: Connect controls to program logic.

tkinter variables

tkinter has its own variable classes (StringVar, IntVar, DoubleVar) with .get(), .set(...).

Widgets support these, e.g. with Label widget's textvariable constructor argument.

Can ask to call a function of three arguments when a variable is changed:


scale widget

This widget's constructor accepts many args, including:

  • from_ — minimum value
  • to — maximum value
  • variable — variable in which to store slider value
  • command — function to call on change

Not covered

A big topic we didn't discuss is adding menus to tkinter applications.

TkDocs has a nice discussion and tutorial.


Revision history

  • 2020-11-23 Initial publication