我想在新窗口中显示图像,但出现错误。
这是我的错误代码
photo = PhotoImage(file='img/dog')
File "C:\Users\Hyojae\Anaconda3\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Hyojae\Anaconda3\lib\tkinter\__init__.py", line 3486, in __init__
raise RuntimeError('Too early to create image')
RuntimeError: Too early to create image
这是我的代码示例。
我会很感激你的帮助。
from tkinter import *
def messageWindow():
win = Tk()
win.geometry('300x200')
root.destroy()
photo2 = PhotoImage(file="img/dog1.gif")
label1 = Label(win, image=photo2)
label1.grid(row=6)
Button(win, text='OK', command=win.destroy).grid(row = 5, columnspan = 2)
win.mainloop()
root = Tk()
photo = PhotoImage(file="img/dog2.gif")
label1 = Label(root, image=photo)
label1.pack()
Button(root, text='Bring up Message', command=messageWindow).pack()
root.mainloop()
30秒到达战场
相关分类