getting an image-bearing widget to refresh its image (bonus question: at regular intervals)

Jon Schull schull at digitalgoods.com
Mon Jul 29 12:12:37 EDT 2002


Can anyone tell me why this code fails to display b2.gif...
------------------------------------------
from Tkinter import *
root = Tk()
root.title("Images")

picture = PhotoImage(file="c:\\temp\\buchananst.GIF")
L1=Label(root, image=picture)
L1.grid()

def update():
 global b
 print 'update'
 pic2 = PhotoImage(file="c:\\temp\\b2.gif")
 L1.config(image=pic2)
 L1.grid(row=3,column=0)
 b.config(text="updated")

b=Button(root,text='update', command=update)
b.grid()


#showpic()
root.mainloop()
------------------------------------------

...whereas if instead of  b.config(text="updated") I write
b[text]="updated", I get an error message on that line AND b2.gif *IS*
updated?

Is there a right way to get an image-bearing widget to load a new (or
updated) image?
...at regular intervals?  (I'm currently planning on using Threads.py
at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 )

Thanks!



More information about the Python-list mailing list