如何删除编辑 TKinter 小部件 Python

How to remove edit TKinter widget Python

我正在尝试为一个无用的刽子手游戏设置简单的框架,图像以 6 个系列命名,用于失败的每个阶段。 S0是开始,S6是最后阶段。

我正在想办法更新照片。

from tkinter import *
from PIL import ImageTk, Image

root = Tk()
i=0

frameLeft = Frame(root)
frameRight = Frame(root)
frameRight.pack(side=RIGHT)
frameLeft.pack(side=LEFT)

#frame Left

#function Declaration
entry1 = Entry(frameLeft)
entry1.pack()
def updatePhoto():
        i = entry1.get()
        img = ImageTk.PhotoImage(Image.open("S" + i + ".gif"))
        imgPanel = Label(frameRight, image = img)
        imgPanel.pack(side=BOTTOM, fill=BOTH, expand=YES)
labelInstruction = Label(frameLeft, text=entry1.get())
labelInstruction.pack()
submitButton = Button(frameLeft, text="Submit", command=updatePhoto)
submitButton.pack()

#frame Right

img = ImageTk.PhotoImage(Image.open("S" + str(i) + ".gif"))
imgPanel = Label(frameRight, image = img)
imgPanel.pack(side=BOTTOM, fill=BOTH, expand=YES)

root.mainloop()

而不是这些行:

imgPanel = Label(frameRight, image = img)
imgPanel.pack(side=BOTTOM, fill=BOTH, expand=YES)

我能够使用这些

imgPanel.configure(image=img)
imgPanel.image = img

我还更改了左侧和右侧的顺序,使右侧在前,因为它是一种脚本语言,需要声明。