[Tutor] animation with Tkinter canvas

W W srilyk at gmail.com
Tue Mar 3 13:02:07 CET 2009

On Tue, Mar 3, 2009 at 3:05 AM, Mr Gerard Kelly
<gerard.kelly at uqconnect.edu.au> wrote:
> Hello, I am attempting to make a simple animation of a vibrating string using Tkinter canvas.
> I haven't been able to find much information on how to do it.
> I have my data of position x on the string at time t. I can plot it
> with<snip>
> root.update()
> canvas.pack()
> mainloop()
> Now I know that to get animation involves a root.update() and a root.update_idletasks() somewhere but I can't figure out how to use these!

You don't have to use root.update. If you're drawing items on a canvas
you can delete them later.

34: for x in xrange(0, 10):
35:     y = c.create_line(0,0, x*x, x*x)
36:     time.sleep(.5)
37:     c.update_idletasks() #Force redraw
38:     c.delete(y)

Try those 5 lines and see if it works for you.


More information about the Tutor mailing list