PYTHON3.5,tkinter,一直提示image "pyimage1" doesn't exist 我的1.png是存在的,请问为什么会这样?

from tkinter import *
def a():
root = Tk()
image1 = PhotoImage(file = '1.png')
Label1 = Label(root,image = image1)
Label1.pack()
root.mainloop()
def play():
top = Tk()
Button1 = Button(top,command = a)
Button1.pack()
top.mainloop()
play()

第1个回答  2016-12-19
改成绝对路径试一下咯追问

不行……

追答

from os.path import exists
fname='1.png'

print(exists(fname))
用这个测试一下先吧

追问

True

追答

tk()不能重复出现两次
把def a函数里的
root = Tk()

改成root=Toplevel()
就好了。
参考:http://stackoverflow.com/questions/26097811/image-pyimage2-doesnt-exist

第2个回答  2018-07-15
def a():
root = Toplevel()
相似回答