Python tkinter 中多线程用Image.open()重复打开同一个图片,只有第一个弹窗显示图片,怎么解决。程序类似于制作无限弹窗,不过是需要弹出有图的弹窗。
import tkinter as tk
from PIL import Image,ImageTk
import threading
import time
#按比例缩放
def get_image(filename,width,height):
fp = open(filename,'rb')
print(fp)
im = Image.open(fp).resize((width,height))
im_im = ImageTk.PhotoImage(im)
fp.close()
return im_im
def dow():
window = tk.Tk()
window.title("牛牛")
window.geometry("400x400")
# image = Image.open("lwt.png")
# photo = ImageTk.PhotoImage(image)
photo = get_image("lwt.png",400,400)
theLabel = tk.Label(image=photo,compound = tk.CENTER)
theLabel.pack()
window.mainloop()
threads = []
for i in range(5):
t = threading.Thread(target=dow)
threads.append(t)
time.sleep(0.1)
threads[i].start()