Python 未找到文件,即使目录正确

Python 未找到文件,即使目录正确,python,file,directory,Python,File,Directory,我目前正在尝试制作一个游戏,我正在从python文件所在的文件夹导入按钮的图像。方法: dirname, filename = os.path.split(os.path.abspath(sys.argv[0])) imagepath = os.path.join(dirname, "redvase.png") vase1 = Button(root, relief=FLAT, background="white", image=imagepath) vase1.place(x=330,y=24

我目前正在尝试制作一个游戏,我正在从python文件所在的文件夹导入按钮的图像。方法:

dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))
imagepath = os.path.join(dirname, "redvase.png")
vase1 = Button(root, relief=FLAT, background="white", image=imagepath)
vase1.place(x=330,y=240,height=30,width=30)
输出图像路径显示为C:\Users\-\Desktop\Pythonproject\redvase.png

我的文件就在那个确切的路径上,但我仍然收到一个错误,说那个文件不存在

vase1 = Button(root, relief=FLAT, background="white", image=imagepath)
......
_tkinter.TclError: image "C:\Users\- -\Desktop\Pythonproject\redvase.png" doesn't exist

如果有帮助的话,我正在使用Windows和Python 3.4.3。

按钮的图像属性获取图像对象的输入,而不是图像文件的路径。 为了获得图像,您可以使用照片图像:

photo=PhotoImage(file="redvase.gif")
vase1 = Button(root, relief=FLAT, background="white", image=photo)

我也有同样的问题。我创建了目录,但它说找不到。我的代码如下:

import os
os.mkdir("FireFiles")
os.chdir("Python/FireFiles")
f=open("2015BahiaFires.txt", "w")
f.write("Month /tNumber")
f.close

您是否100%确定它是png而不是jpg,并且名称拼写正确?您是否还检查了该文件的文件权限?是否可以使用Python open函数打开该文件?是否确定image=参数采用文件名,而不是图像对象?我不熟悉TkInter的这种级别。Tk库不支持.gif以外的任何其他格式。你试过使用.gif吗?使用非gif文件最简单的方法是使用枕头。它知道如何读取各种格式的图像,并创建Tkinter知道如何使用的ImageTk。通常是你想要的。