jpeg files displayed in a loop

xtian xtian at toysinabag.com
Tue Dec 11 23:16:47 EST 2001


Fernando Pérez <fperez528 at yahoo.com> wrote in message news:<9v5ro0$2hr$1 at peabody.colorado.edu>...
> Kevin Cazabon wrote:
> 
> Well, you got me curious. Here is the code with some things corrected. This 
> actually runs, but it hangs at the first image. My cpu usage pegged at 100% 
> and I just had to kill the job, it wasn't going anywhere. Any ideas?
> 
> 
<snip>
> 
> def showimage():
>     image = files.pop()
>     files.append(image)
>     image = ImageTk.PhotoImage(Image.open(image)) #ok, do try/except
>     b.configure(image=image)
>     b.update_idletasks()
>     b.after(1000, showimage)
> 
> a = Tkinter.Tk()
> b = Tkinter.Label(a)
> b.pack()
> 
> files = os.listdir(dir) # ok, check them for file types...
> os.chdir(dir)
> while 1:
>     showimage()

It's even simpler than what you've got - you don't need to call
showimage in a loop. All you need to do is call it once and then call
mainloop().
Because each call to showimage schedules the next call with after(),
you've got an infinite loop anyway.

You're getting big cpu usage because you're setting up a whole heap of
callsback to the function, but never letting the event loop run to
process them.

Pretty cool, though.

xtian



More information about the Python-list mailing list