我有这个代码:
def Annabeth():
Annabeth= Tk()
Annabeth.geometry('450x450')
says = Label(Annabeth,text ='I was just making a general statement!')
says.pack(side=BOTTOM)
img = ImageTk.PhotoImage(Image.open('C:/Users/Geekman2/Pictures/Pictures/Annabeth.jpg'))
image1 = Label(Annabeth,image=img)
image1.pack()
Annabeth.mainloop()
它位于模块中
rox
当我调用
Annabeth()
我的窗口出现,它显示图像,一切正常。当我从另一个模块使用代码时
from rox import*
Annabeth()
它工作得很好但是当我使用这段代码时
def callback():
Annabeth()
game = Tk()
game.geometry('50x50+700+100')
Button1 = Button(game,text = '1',command =callback )
Button1.pack(side=LEFT)
game.mainloop()
窗口显示,但图片不显示,我得到错误
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1974, in __init__
(widgetName, self._w) + extra + self._options(cnf))
TclError: image "pyimage1" doesn't exist
对于我的一生,我无法弄清楚是什么原因造成的,显然我不应该在 GUI 程序中有多个主循环,但是我应该怎么做呢?