Python & Tkinter -> About calling a long running function that freeze the program Python & Tkinter -> About calling a long running function that freeze the program tkinter tkinter

Python & Tkinter -> About calling a long running function that freeze the program


The problem is simple: BUT1 won't return until the call to main returns. As long as main (and thus, BUT1) doesn't return, your GUI will be frozen.

For this to work you must put main in a separate thread. It's not sufficient that main spawns other threads if all it's doing is waiting for those threads.


If you call root.update() occasionally from the BUT1 function, that should prevent the GUI from freezing. You could also do that from a python thread with a fixed interval.

For example, updating every 0.1 seconds:

from threading import Threadfrom time import sleepself.updateGUIThread = Thread(target=self.updateGUI)def updateGUI(self):    while self.updateNeeded        root.update()        sleep(0.1)

After the big function completes you can set self.updateNeeded to False.