简体   繁体   English

如何删除编辑TKinter小部件Python

[英]How to remove edit TKinter widget Python

Im trying to set up simple frame work for a trashy hang man game, the images are named in series of 6 for each stage of failure. 我正在尝试为垃圾桶吊人游戏设置简单的框架,每个失败阶段的图像以6个系列命名。 S0 is the beginning and S6, is the final stage. S0是开始,S6是最后阶段。

Im trying to figure out how to upudate the photo. 我试图弄清楚如何更新照片。

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()

Instead of these lines: 代替这些行:

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

I was able to use these 我能够使用这些

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

I also changed the order of left and right side making right come first as it's a scripting language and requires declaration. 我还更改了左侧和右侧的顺序,使右侧优先,因为它是一种脚本语言,需要声明。

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

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