469,923 Members | 1,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Tkinter slowes down

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?

--
geon
The exception is rule.
Jul 19 '05 #1
4 2824
"pavel.kosina" <ge**@post.cz> wrote:
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>

Jul 19 '05 #2
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

--
geon
Vyjímka je pravidlo. Rekurzivní.
Jul 19 '05 #3
On Sat, 28 May 2005 18:21:46 +0200, pavel.kosina <ge**@post.cz> wrote:
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".

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
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\\'*9--56l7+-'])"
Jul 19 '05 #4
Eric Brunel wrote:
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.


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_....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>

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by srijit | last post: by
7 posts views Thread by SeeBelow | last post: by
2 posts views Thread by Russell E. Owen | last post: by
3 posts views Thread by phil | last post: by
2 posts views Thread by Andrew Trevorrow | last post: by
1 post views Thread by Michael Yanowitz | last post: by
7 posts views Thread by Peter Pearson | last post: by
3 posts views Thread by J-Burns | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.