所以我需要在我用 python 创建的按钮上获取我的图像。但它弹出错误(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist
。另外,我已经在一个函数中制作了我的程序的主窗口。然后我做到了,所以当 python 完成该功能时,它会打开这个启动窗口,您可以在其中登录并访问LifeLoginWindow
. 但是当我摆脱这个启动并调用该LifeLoginWindow
函数时,它运行完美,我可以看到图像。所以我不知道发生了什么。这是我的代码:
from tkinter import*
def hello():
print("Works, and hello!")
def LifeLoginWindow():
window = Tk()
TrendsButton = PhotoImage(file = "Trends_Button.png")
TrendsButton_label = Button(SideBar, image = TrendsButton, command = hello)
TrendsButton_label.pack(side=TOP)
SideBar.pack(side = LEFT, fill = Y)
window.mainloop()
StartUp = Tk()
def LoginFunction():
StartUp.destroy
LifeLoginWindow()
StartUpIcon = PhotoImage(file = "Life Login Image Resized.png")
StartUpIcon_label = Label(StartUp, image = StartUpIcon)
StartUpIcon_label.grid(row = 0, column = 2)
LoginButt = Button(StartUp, text = "Login", command = LoginFunction)
LoginButt.grid(row = 3, column = 2)
print("_Loaded Start Up...")
StartUp.mainloop()