<font size=2 face="sans-serif">Hello Nemes:</font>
<br>
<br><font size=2 face="sans-serif">The issue with the code as written is
that the infinite while loop begins execution before the root.mainloop()
ever gets called (so root.mainloop never gets called....).</font>
<br>
<br><font size=2 face="sans-serif">To start the animation AFTER the root.mainloop()
call, I've moved the animation work into a function and used the after
method to call that function after the mainloop initiates.</font>
<br>
<br><font size=2 face="sans-serif">Also, instead of using a while loop
with a sleep call (which hangs the program while waiting), I've changed
the animation function to call itself each time it finishes. This
way the program doesn't hang while animating the picture, which is useful
if you want this to be part of a larger program.</font>
<br>
<br><font size=2 face="sans-serif">Hope this is helpful!</font>
<br>
<br><font size=2 face="sans-serif">Dave Giesen</font>
<br>
<br>
<br>
<br><font size=2 face="sans-serif">#Working on window interface of soundAsleep</font>
<br>
<br><font size=2 face="sans-serif">#Tkinter will handle the GUI</font>
<br><font size=2 face="sans-serif">from Tkinter import *</font>
<br>
<br><font size=2 face="sans-serif">root = Tk()</font>
<br><font size=2 face="sans-serif">root.title("soundAsleep beta")</font>
<br>
<br><font size=2 face="sans-serif">frame=[]</font>
<br>
<br><font size=2 face="sans-serif">#Importing the images. They are named
w1.gif, w2.gif...w7.gif</font>
<br><font size=2 face="Verdana">for i in range(1,7):</font>
<br><font size=2 face="Verdana"> fname="core/working/w"+str(i)+".gif"</font>
<br><font size=2 face="Verdana"> frame+=[PhotoImage(file=fname)]</font>
<br>
<br><font size=2 face="sans-serif">wrap = Canvas(root, width=200, height=120)</font>
<br><font size=2 face="sans-serif">wrap.pack()</font>
<br>
<br><font size=2 face="sans-serif">def do_animation(currentframe):</font>
<br><font size=2 face="sans-serif"> def
do_image():</font>
<br><font size=2 face="sans-serif">
wrap.create_image(100,70,image=frame[currentframe],
tag='ani')</font>
<br><font size=2 face="sans-serif"> #
Delete the current picture if one exists</font>
<br><font size=2 face="sans-serif">
wrap.delete('ani')</font>
<br><font size=2 face="sans-serif"> try:</font>
<br><font size=2 face="sans-serif">
do_image()</font>
<br><font size=2 face="sans-serif"> except
IndexError:</font>
<br><font size=2 face="sans-serif">
# End of image list reached, start over at
the first image - works for an arbitrary number of images</font>
<br><font size=2 face="sans-serif">
currentframe = 0</font>
<br><font size=2 face="sans-serif">
do_image()</font>
<br><font size=2 face="sans-serif">
wrap.update_idletasks() #Force redraw</font>
<br><font size=2 face="sans-serif"> currentframe
= currentframe + 1</font>
<br><font size=2 face="sans-serif"> #
Call myself again to keep the animation running in a loop</font>
<br><font size=2 face="sans-serif"> root.after(5000,
do_animation, currentframe)</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"># Start the animation loop just after
the Tkinter loop begins</font>
<br><font size=2 face="sans-serif">root.after(10, do_animation, 0)</font>
<br>
<br><font size=2 face="sans-serif">root.mainloop()</font>
<br>
<p><font size=1 face="Arial"><b>David J. Giesen</b> | Research Scientist
| FPEG US Display OLED Materials R+D | <br>
Eastman Kodak Company | 2/83/KRL MC02216 | Rochester, NY 14650 | </font><font size=1 color=blue face="Arial"><u><br>
</u></font><a href=mailto:david.giesen@kodak.com><font size=1 color=blue face="Arial"><u>david.giesen@kodak.com</u></font></a><font size=1 face="Arial">
| 1-585-588-0480 Office | </font><font size=1 color=blue face="Arial"><u><br>
</u></font><a href=http://www.kodak.com/><font size=1 color=blue face="Arial"><u>www.kodak.com</u></font></a><font size=1 face="Arial">
<br>
</font><img src=cid:_1_12DF49C812DF3F740066BD6185257694>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Nemes Andrei <teh_sh_meister@yahoo.com></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">tkinter-discuss@python.org</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">12/22/2009 10:47 AM</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">[Tkinter-discuss] Animation using image
sequence</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Sent by:</font>
<td><font size=1 face="sans-serif">tkinter-discuss-bounces+david.giesen=kodak.com@python.org</font></table>
<br>
<hr noshade>
<br>
<br>
<br><font size=2 face="Verdana">Hi!</font>
<br>
<br><font size=2 face="Verdana">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?</font>
<br><font size=2 face="Verdana">Help would be greatly appreciated. Thank
you.</font>
<br>
<br><font size=2 face="Verdana">#Working on window interface of soundAsleep</font>
<br>
<br><font size=2 face="Verdana">#Tkinter will handle the GUI</font>
<br><font size=2 face="Verdana">from Tkinter import *</font>
<br><font size=2 face="Verdana">import time</font>
<br>
<br><font size=2 face="Verdana">root = Tk()</font>
<br><font size=2 face="Verdana">root.title("soundAsleep beta")</font>
<br>
<br><font size=2 face="Verdana">frame=[]</font>
<br><font size=2 face="Verdana">currentframe=0</font>
<br>
<br><font size=2 face="Verdana">#Importing the images. They are named w1.gif,
w2.gif...w7.gif</font>
<br><font size=2 face="Verdana">for i in range(1,7):</font>
<br><font size=2 face="Verdana"> fname="core/working/w"+str(i)+".gif"</font>
<br><font size=2 face="Verdana"> frame+=[PhotoImage(file=fname)]</font>
<br>
<br><font size=2 face="Verdana">wrap = Canvas(root, width=200, height=120)</font>
<br><font size=2 face="Verdana">wrap.pack()</font>
<br>
<br><font size=2 face="Verdana">#trying to make the animation</font>
<br><font size=2 face="Verdana">while True:</font>
<br><font size=2 face="Verdana"> ani=wrap.create_image(100,70,image=frame[currentframe])</font>
<br><font size=2 face="Verdana"> time.sleep(5)</font>
<br><font size=2 face="Verdana"> wrap.update_idletasks() #Force
redraw</font>
<br><font size=2 face="Verdana"> wrap.delete(ani)</font>
<br><font size=2 face="Verdana"> if (currentframe==5):</font>
<br><font size=2 face="Verdana"> currentframe=0</font>
<br><font size=2 face="Verdana"> else:</font>
<br><font size=2 face="Verdana"> currentframe+=1</font>
<br><font size=2 face="Verdana"> </font>
<br><font size=2 face="Verdana">root.mainloop()</font>
<br>
<br><tt><font size=2>_______________________________________________<br>
Tkinter-discuss mailing list<br>
Tkinter-discuss@python.org<br>
</font></tt><a href="http://mail.python.org/mailman/listinfo/tkinter-discuss"><tt><font size=2>http://mail.python.org/mailman/listinfo/tkinter-discuss</font></tt></a><tt><font size=2><br>
</font></tt>
<br><font size=2 face="sans-serif"><br>
</font>