Tkinter long-running window freezes

John O'Hagan research at johnohagan.com
Wed Feb 24 18:53:55 EST 2021


On Wed, 24 Feb 2021 11:03:30 -0500
Terry Reedy <tjreedy at udel.edu> wrote:

> On 2/24/2021 6:35 AM, John O'Hagan wrote:
[...]
> 
> I am trying this out on Windows 10, with a wider label (so I can move 
> the window) and a button that changes when pressed, and a sequential 
> counter.  Will report when the Window freezes, or maybe a day if not.

Thank you! I've only run a few tests because of how long it takes
to freeze, but so far it seems that the trigger for the window freezing
is any attempt to interact with it, e.g. clicking on it, so try doing
that from time to time.

> > from tkinter import *
> > from random import randint
> > 
> > root = Tk()
> > 
> > def display(label):
> >      label.destroy()
> >      label = Label(text=randint(0, 9))
> >      label.pack()
> >      root.after(100, display, label)
> > 
> > display(Label())
> > mainloop()  
> 
> You could try with .grid instead.

I used .pack in the example for simplicity, but in the real application
where I first saw the problem, I am already using .grid.
 
> 
> Plus you seem to have a memory leak and may need to replicate that.

Can you explain what you mean by "replicate"? Each time I run the code
snippet above, I get a similar gradual increase in memory use by the
process. Surely it can't be that little bit of Python code that's
causing it - it must be something in tkinter? Or X11? 

> > This works for 3-4 hours, but eventually the window freezes.
> > 
> > The process uses about 26 Mb of memory at first, and this gradually
> > increases to around 30 or so by the time it freezes.  
> 

Thanks

--

John


More information about the Python-list mailing list