[Tkinter-discuss] Tkinter GUI freezing

Wayne Werner wayne at waynewerner.com
Fri Apr 20 15:08:04 CEST 2012

On Thu, 19 Apr 2012, Bharath Reddy A. wrote:

> Hi all,I have created a GUI using Tkinter. 
> I have a button "GO", which when clicked calls a function (mainFunc).
> That function takes around 60 seconds to execute and in the mean time outputs many numbers which have to be
> displayed in a list in the GUI.
> I have attempted the following:
>  1.  I created a thread whose target = mainFunc, when the button is clicked. I can see the function printing
>     stuff in terminal. But the GUI still freezes.
>  2.  When I tried to create a  thread whose target = root.mainloop(), the GUI doesn't display at all,
>     (Python.app launches but the GUI is not displayed), 
> Can you please help me how to create threads exactly???

You probably don't *really* want to execute a separate thread - it's 
usually a better idea to let Tkinter handle the parallelism. You can use 
the .after function (I think the syntax would be main.after(10, 
mainFunction) for your application, but Google will confirm), and then the 
.update_idletasks in your mainFunction. I'm assuming there's a loop 
involved (I haven't taken a look at your code), so you could launch that 
once every iteration of your loop.

It's been a while since I've had the pleasure of mucking with any of that, 
but it should give you the ability to have a responsive UI while still 
running your function.


More information about the Tkinter-discuss mailing list