tkinter - Exit Tks mainloop in Python? -
i'm writing slideshow program tkinter, don't know how go next image without binding 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) 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 add time.sleep(10) "instead" of root.mainloop(0) go next image after 10s. changes when press esc. how can have timer there?
edit: should add don't want thread sleep though works.
you can try
root.after(10*1000, root.quit)
Comments
Post a Comment