Tkinter slowes down

P

pavel.kosina

It seems to me that in my "again and again repainting canvas" script the
rendering is slowing down as the time goes.

It is visible even after 10 seconds.
Any idea why?
 
F

Fredrik Lundh

pavel.kosina said:
It seems to me that in my "again and again repainting canvas" script the
rendering is slowing down as the time goes.

when you add an item to the canvas, it's part of the canvas
until you remove it. if performance drops, it's usually because
you keep adding new items without removing the old ones.

try adding a w.delete(ALL) call before you "repaint".

for better performance, you should restructure your code so
it modifies existing canvas items, when possible, rather than
deleting and recreating items all the time.

if you want a light-weight canvas, you might wish to look at

http://effbot.org/zone/wck.htm

and especially

http://effbot.org/zone/wck-3.htm

</F>
 
P

pavel.kosina

Fredrik Lundh napsal(a):
when you add an item to the canvas, it's part of the canvas
until you remove it. if performance drops, it's usually because
you keep adding new items without removing the old ones.

try adding a w.delete(ALL) call before you "repaint".

In the meantime I found that widget.destroy() works well, too (before
"repainting").

Thanks a lot
 
E

Eric Brunel

Fredrik Lundh napsal(a):

I noticed once that if this actually deletes all canvas items, it does not delete the bindings on them: every binding put on a canvas item registers a Python callable at tcl level, but does not associate it with the item. So deleting the item keeps the binding even if it cannot be called anymore. If you have many items with several bindings, this can cause the memory usage to grow up and slow down the canvas.
In the meantime I found that widget.destroy() works well, too (before
"repainting").

This was the only solution I found using "regular" Tkinter widgets when there are bindings on canvas items. I tried to find another solution by modifying Tkinter.py, but the problem is much harder than it seems, since many things happen at tcl level. However, I didn't investigate the WCK.

HTH
 
F

Fredrik Lundh

Eric said:
This was the only solution I found using "regular" Tkinter widgets when
there are bindings on canvas items. I tried to find another solution by
modifying Tkinter.py, but the problem is much harder than it seems,
since many things happen at tcl level.

for pure Tkinter, I recommend using bind classes to implement "controllers"
on the canvas level, using appropriate find functions to locate the individual
items, and dispatching via "trackers". see

http://online.effbot.org/2004_09_01_archive.htm#wck-track

for some background (I guess it's time to write that "later article" I mention
in that article. if you cannot wait, feel free to steal the controller code from
the WCK).

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,240
Messages
2,571,211
Members
47,845
Latest member
vojosay

Latest Threads

Top