Skip to content Skip to sidebar Skip to footer

Why Does Tkinter / Window.update Get Slower Over Time Within My Program?

I find that when I call window.update, it operates much faster when fewer things have been written to the window, but then later on, when I have written more elements to the window

Solution 1:

Short answer:

That is due to the complexity of the algorithm you use.

Detailed answer:

The while condition is indefinitely satisfied.

Right away after the for loop exits, you ask the canvas to redraw all the previous ovals.

This means:

  • while iteration 1, canvas redraws 99 ovals
  • while iteration 2: canvas redraws 99 + 99 ovals
  • while iteration 3: canvas redraws 99 + 99 + 99 ovals.
  • while iteration 4: canvas redraws 99 + 99 + 99 + 99 ovals.
  • ...
  • ... OMG !!!

Conclusion

You got what you asked for.

Alternative

If you want to keep drawing only 99 ovals indefinitely, then delete each previous 99 ovals you previously created. This means, you can add canvas.delete(ALL) right below canvas.update()

Post a Comment for "Why Does Tkinter / Window.update Get Slower Over Time Within My Program?"