我正在尝试在 tkinter 中渲染图像。我已经看到很多关于如何制作图像的堆栈溢出脚本,但是当我尝试时它说我的图片不存在。是否有某个地方我必须存储我的图像?我的 python 脚本保存到桌面,但我知道 python 可能不会在那里搜索。我应该把我想在我的程序中显示的图像放在哪里?提前致谢!
编辑:这是请求的代码:
canvas = Canvas(app, width=300, height=250).pack()
picture = PhotoImage(file='image.gif') #image located in desktop
canvas.create_image(0,0, image = picture
这是错误:
Traceback (most recent call last):
File "/Users/theroeloffs/Downloads/myprogram.py", line 87, in <module>
piper_pic=PhotoImage(file = 'image.gif')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 3306, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 3262, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "image.gif": no such file or directory
抱歉,出于某种原因,该网站不允许我编写该代码
PS我有一个mac