Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我将在python脚本中使用的图像存储在哪里?_Python_User Interface_Python 2.7_Tkinter - Fatal编程技术网

我将在python脚本中使用的图像存储在哪里?

我将在python脚本中使用的图像存储在哪里?,python,user-interface,python-2.7,tkinter,Python,User Interface,Python 2.7,Tkinter,我试图在tkinter中渲染图像。我见过很多关于如何制作图像的脚本,但是当我尝试时,它说我的图片不存在。是否有某个地方我必须存储我的图像?我的python脚本保存到桌面,但我知道python可能不会在那里搜索。我要在程序中显示的图像放在哪里?提前谢谢 编辑:以下是请求的代码: canvas = Canvas(app, width=300, height=250).pack() picture = PhotoImage(file='image.gif') #image located in des

我试图在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
回溯(最近一次呼叫最后一次):
文件“/Users/theroeloffs/Downloads/myprogram.py”,第87行,在
piper_pic=PhotoImage(文件='image.gif')
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py”,第3306行,在__
图像。_u初始(自我,“照片”,名称,cnf,主机,**千瓦)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py”,第3262行,在__
self.tk.call(('image','create',imgtype,name,)+选项)
Tcl错误:无法打开“image.gif”:没有这样的文件或目录
出于某种原因,本网站不允许我制作该代码


另外,我有一台mac电脑

您可以使用绝对路径:

picture = PhotoImage(file='/Users/theroeloffs/Desktop/image.gif')
或者更好的版本是,将图像复制到此位置:

/Users/theroeloffs/Downloads/image.gif
(脚本所在的位置)并且只能使用文件名:

picture = PhotoImage(file='image.gif')

只需将它与脚本放在同一个文件中


希望有帮助

请在那里显示您试图使用图像的代码。最干净的方法是将路径(例如,
image\u dir=…
)存储在配置文件中,然后导入配置文件。阅读Python中的配置文件。