原因
最近因为要写个GUI的内容,需要用到图像的遍历显示,因为没有办法,所以就自行摸索着开始写一个循环显示的TK。最终算是不符所望吧,勉强写出来一个,以此做下记录,便于下次使用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import tkinter as tk from PIL import ImageTk, Image import glob, time import threading
filenames = glob.glob('sysImages/*')
def autoQuit(): time.sleep(2) root.quit()
for filename in filenames: root = tk.Tk()
img = Image.open(filename) photo = ImageTk.PhotoImage(img) label = tk.Label(image=photo) label.image = photo label.pack()
t = threading.Thread(target=autoQuit) t.start() root.mainloop() root.destroy()
|