Lecture 40

GUIs with tkinter 3

MCS 260 Fall 2020
Emily Dumas

Reminders

  • Worksheet 14 and solutions available
  • Quiz 14 (the last one!) available, due Monday
  • Project 4 submissions open in Gradescope

Idle

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 for the letter rotation code we developed in Lecture 36 & Lecture 38.

So far: Built GUI controls, set up one callback.

Remaining: More callbacks to make slider display and slider work.

Review

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:

varobj.trace_add("write",func_to_call)

Window title

tkinter.Tk has a method .title(s) which sets the window title to s.

The window title is usually shown in the window's top bar, and possibly in a dock/taskbar as well.

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.

References

Revision history

  • 2020-11-25 Additional reminders
  • 2020-11-24 Initial publication