from tkinter import *
root = Tk()
photo = PhotoImage(file='blueface.png')
label = Label(root, image=photo)
label.pack()
root.mainloop()
图片face.png与此.py脚本在同一目录中,但运行时出现以下错误:
line 5, in <module>
photo = PhotoImage(file='blueface.png')
line 3539, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
line 3495, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "face.png": no such file or directory
blueface.png
,但是你的文本描述提到了face.png
。那个是正确的? - John Gordon