Home > Software engineering >  Is .after function in Tkinter makes you run the function on background?
Is .after function in Tkinter makes you run the function on background?

Time:05-25

When you run a function using .after() in Tkinter, does it stop all the current tasks and run that function or does it run it as a background task? So, if I want to run a function as a background task (meaning it won't make the process to stuck while it is running), what should I do?

CodePudding user response:

Tkinter is single-threaded. It is an event-based architecture that maintains a queue of events to be processed. These events are processed in order.

The use of after does nothing more than putting an event on the queue with a timestamp. During normal processing of the queue, tkinter will invoke a function once the interval has passed. Tkinter will not be able to do anything while that function is running.

These functions do not run in the background. A better way of looking at it is that they run in the gaps between doing other things.

If you need something to run in the background you'll need to use threading or multiprocessing.

  • Related