Lecture 43

Threads in tkinter GUIs

MCS 260 Fall 2020
David Dumas

Reminders

  • Please complete a course evaluation.
  • Project 4 is due today at 6pm central.
  • Worksheet 15 and Quiz 14 solutions posted recently.
  • No TA or instructor office hours next week.

After today

  • Blackboard site stays up until Dec 31.
  • My MCS 260 site stays up "forever" and has everything except the videos.
  • I can't make the lecture videos public unless they are edited (to protect student privacy). Editing is slow.
  • I'll email you if I start posting edited lecture videos publicly.

GUI work so far

Threading so far

Today

We saw in Lecture 40 that the encoder doesn't perform well if encoding is slow: The GUI is unresponsive.

Today we'll make it multi-threaded so the GUI remains responsive while encoding is in progress.

  • Main thread: GUI main loop
  • Worker thread: Perform encoding as needed

Step 1

Let's move the program logic that updates the output (performing encoding) to its own object.

This new object is the model, which stores and updates the key data the interface uses.

Step 2

Have the model do its encoding in a separate thread.

Use threading.Event to request encoding.

What else could we do?

  • Perform encoding using an API (the way most actions in mobile apps occur)
  • Make auto-update an option (settings menu?) with button to manually update if auto is disabled
  • Make an application icon
  • Make a button to switch to inverse (decode the current rotation)

References

Revision history

  • 2020-12-03 Initial publication