[Tkinter-discuss] Animation using image sequence

Nemes Andrei teh_sh_meister at yahoo.com
Tue Dec 22 14:56:19 CET 2009


Hi!

I'm trying to make an animation using a sequence of gif images and the canvas widget, but all I see when I compile is a black screen. What I'm trying to do is delete the previous image and create the next one each frame. Am I doing it wrong? Is it do-able at all?
Help would be greatly appreciated. Thank you.

#Working on window interface of soundAsleep

#Tkinter will handle the GUI
from Tkinter import *
import time

root = Tk()
root.title("soundAsleep beta")

frame=[]
currentframe=0

#Importing the images. They are named w1.gif, w2.gif...w7.gif
for i in range(1,7):
    fname="core/working/w"+str(i)+".gif"
    frame+=[PhotoImage(file=fname)]

wrap = Canvas(root, width=200, height=120)
wrap.pack()

#trying to make the animation
while True:
    ani=wrap.create_image(100,70,image=frame[currentframe])
    time.sleep(5)
    wrap.update_idletasks() #Force redraw
    wrap.delete(ani)
    if (currentframe==5):
        currentframe=0
    else:
        currentframe+=1
    
root.mainloop()



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20091222/eb03fe36/attachment.htm>


More information about the Tkinter-discuss mailing list