我正在尝试建立一个接收窗口,创建Frame
并在此框架内添加图像的类。
如果我在课堂外这样做,认为效果很好。
情况1:
window = Tk()
window.title('Interactive Dictionary')
logo_frame = Frame(window, bg='yellow')
logo_frame.pack()
img = Image.open("static/app_image.jpg")
img = ImageTk.PhotoImage(image=img)
panel = Label(logo_frame, image=img)
panel.grid(row=0, column=0)
window.mainloop()
但是,当我将代码放入类中时,认为停止工作:
情况2:
class Gui:
def __init__(self, master=None):
if master is None:
return
else:
self.logo_frame = Frame(master, background='#fff')
self.logo_frame.grid()
img = Image.open("static/app_image.jpg")
img = ImageTk.PhotoImage(image=img)
panel = Label(self.logo_frame, image=img)
panel.grid(row=0, column=0)
if __name__ == '__main__':
window = Tk()
window.title('Interactive Dictionary')
app = Gui(master=window)
window.mainloop()
我该怎么办?