I'm writing a slideshow program with Tkinter, but I don't know how to go to the next image without binding a key.

import os, sys
import Tkinter
import Image, ImageTk
import time

root = Tkinter.Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.focus_set()

root.bind("<Escape>", lambda e: e.widget.quit())

image_path = os.path.join(os.getcwd(), 'images/')
dirlist = os.listdir(image_path)

for f in dirlist:
    try:
        image = Image.open(image_path+f)
        tkpi = ImageTk.PhotoImage(image)        
        label_image = Tkinter.Label(root, image=tkpi) # ?
        label_image.place(x=0,y=0,width=w,height=h)
        root.mainloop(0)
    except IOError:
        pass
root.destroy()

I would like to add a time.sleep(10) "instead" of the root.mainloop(0) so that it would go to the next image after 10s. Now it changes when I press ESC. Can I have a timer there?

root.after(10*1000, root.quit)

was the solution

You can also use something like
time.sleep(10)
root.update()

instead of
root.mainloop(0)

Thanks, yeah, that also works.

While at it, you don't happen to know how to change the background color of my fullscreen window? It would be nice to have it black instead of light gray.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.