如何删除编辑TKinter小部件Python

时间:2017-08-13 04:45:28

标签: python python-3.x tkinter python-imaging-library pillow

我试图为一个无用的悬挂人游戏设置简单的框架工作,图像以每个故障阶段的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()

1 个答案:

答案 0 :(得分:0)

而不是这些行:

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

我能够使用这些

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

我也改变了左右两侧的顺序,因为它是一种脚本语言,需要声明。