提问者:小点点

Python Tkinter图像定义问题


from tkinter import *
Initimage=Tk()
Initimage.title('Initializing')
photo1=PhotoImage(file='AMAS.gif')
Label(Initimage,image=photo1,bg='black').grid(row=0,column=0,sticky=E)
Initimage.resizable(0,0)

我想把上面的代码实现到def()中:但是它给了我一个错误

(widgetName,self._w)+extra+self._options(cnf))_tkinter.tclerror:映像“PyImage1”不存在

请救命!


共1个答案

匿名用户

函数实现示例,添加了mainloop()以连续显示

from tkinter import *
def displayimage():
    Initimage=Tk()
    Initimage.title('Initializing')
    photo1=PhotoImage(file='AMAS.gif')
    Label(Initimage,image=photo1,bg='black').grid(row=0,column=0,sticky=E)
    Initimage.resizable(0,0)
    Initimage.mainloop()

displayimage()