我想制作一个显示初始图像的程序,然后在文件夹中显示最新图像。
除了 Tkinter 面板在窗口中的第一个图像下方显示最新图像之外,我一切正常。我想不出一种方法来破坏原件或在没有旧图像的情况下制作另一个面板。我复制了下面的相关代码,不确定它是否会无错误地执行。我的 .py 文件运行良好,没有任何错误,只是出现了不需要的结果。任何帮助都会很棒。
from Tkinter import *
import Image, ImageTk
import datetime
import sys, os
FILE_PATH = "C:\\easy\\Pics"
#------------------------------------------------------------------------#
def quitX():
root.destroy()
sys.exit()
#------------------------------------------------------------------------#
def prg_task():
# code section removed....
# continue code
im = Image.open("C:\easy\imageNEW.jpg")
image1 = ImageTk.PhotoImage(im)
# get the image size
w = image1.width()
h = image1.height()+10
# position coordinates of root 'upper left corner'
x = 500
y = 200
# make the root window the size of the image
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# root has no image argument, so use a label as a panel
panel1 = Label(root, image=image1)
panel1.pack(side='top', fill='both')
# put a button on the image panel to test it
button2 = Button(panel1, text='Close Window', command=quitX)
button2.pack(side='bottom')
# save the panel's image from 'garbage collection'
panel1.image = image1
root.after(10000, prg_task)
##########################################################################
# START CODE EXECUTION
# Initializing non-constant global variables
root = Tk()
root.title("Camera")
initIMG = Image.open("C:\easy\No-Image-Available.jpg")
tkimage = ImageTk.PhotoImage(initIMG)
panel1 = Label(root,image=tkimage)
panel1.pack(side='top', fill='both')
#------------------------------------------------------------------------#
# After 0.1s, attempt to grab still image from IP Camera
root.after(100, prg_task)
root.mainloop()
#------------------------------------------------------------------------#