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()
不行……
追答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