

The following program displays a digital clock. A practical Tkinter after() method example Tkinter will execute the callback in the main thread when the main thread is not busy. To prevent a long-running task from blocking the main thread, you can schedule an action that won’t be executed earlier than a specified time by using the after() method. If you start a long-running task in the main thread, the GUI will freeze and don’t respond to user events. It’s responsible for handling events and updating GUI.

The Tkinter’s main loop must start from the main thread. When you launch a Tkinter application, it executes in the main thread.

( 'TButton', foreground=color)Īpp.mainloop() Code language: Python ( python )Ī Python program can have one or multiple threads. Self.button = ttk.Button(self, text= 'Wait 3 seconds')
