【发布时间】:2011-10-03 16:49:41
【问题描述】:
我目前正在使用 PIL 和 Tkinter 来显示图像。我正在从网络传输图像,并希望在进入时自动更新我的窗口(很像图片幻灯片)。我的显示图像代码有效;但是,我必须单击显示窗口上的 [x] 按钮才能更新照片。我希望窗口在新照片出现时自动更新,或者至少每 5 秒运行一次循环(这样窗口要么自行关闭并出现新照片,要么照片只是在窗口中更改)。我的代码是:
##I have a database of photos i want to display one by one...
im=image.open(currentphoto)
root=Tk()
canvas=...
photo=imageTk.PhotoImage(im)
item=canvas.create_image(10,10,anchor=NW,image=photo)
root.mainloop()
##want to display next photo either as it comes in or every 5 seconds (whichever is easier -- first method preferred)
此代码有效;
【问题讨论】:
-
你需要一个计时器和一个回调。
-
您不需要创建计时器——事件循环能够在特定时间点运行代码。
标签: python tkinter python-imaging-library