0
我想製作一個程序來顯示初始圖像,然後在文件夾中顯示最新的圖像。在Python中顯示多個圖像Tkinter按順序
我有一切工作,除了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()
#------------------------------------------------------------------------#
感謝您的幫助。我沒有在Tkinter框架中使用類,所以在您開始撰寫課程之後。截至目前,其中大部分工作。 – santhon88