繁体   English   中英

如何删除编辑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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM