O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Why use a thread with a GUI application?

Graphical applications tend to execute everything in the main thread. This means that updates to its widgets happen in line with all other code that is currently executing.

As a result of this, any slow processing will often block the updating of the GUI. We can demonstrate this with a small example:

import tkinter as tkimport timewin = tk.Tk()win.geometry("200x150")counter = tk.IntVar()label = tk.Label(win, text="Ready to Work")counter_label = tk.Label(win, textvar=counter)

The example starts with a window which will contain a Label displaying the value of an IntVar.

We will be creating a button that increases the value stored in the IntVar, as well as another button which will simulate a very heavy ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required