我正在用 Tkinter 编写一个幻灯片程序,但我不知道如何在不绑定密钥的情况下转到下一个图像。
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()
我想添加一个 time.sleep(10) “而不是” root.mainloop(0) 以便它在 10 秒后转到下一个图像。现在当我按 ESC 时它会改变。我怎么能在那里有一个计时器?
编辑:我应该补充一点,即使它有效,我也不想要另一个睡眠的线程。