我正在尝试将gif导入到Tkinter.Label中。我收到的文件不存在错误。我仔细检查了路径和文件名。
以下是我收到的错误消息。
Traceback (most recent call last):
File "C:\Users\sachin\Desktop\Project California.py", line 39, in <module>
if __name__=='__main__': main()
File "C:\Users\sachin\Desktop\Project California.py", line 35, in main
feedback = Feedback(root)
File "C:\Users\sachin\Desktop\Project California.py", line 11, in __init__
self.logo = PhotoImage(file= "C:\\Users\\sachin\\Desktop\\signature.gif")
File "C:\Users\sachin\AppData\Local\Programs\Python\Python36
\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "C:\Users\sachin\Desktop\signature.gif": no
such file or directory
这是我使用的代码。
def __init__(self,master):
self.frame_header = ttk.Frame(master)
self.logo = PhotoImage(file= "C:\\Users\\sachin\\Desktop\\signature.gif")
ttk.Label(self.frame_header, image = self.logo)
我是python编程中的菜鸟。如果问题太微不足道,请道歉。
答案 0 :(得分:0)
我得到了同样的错误,我确信路径也是正确的。实际上,它似乎每次尝试都会找到该文件,代码非常相似。
for r in range(0,5):
for c in range(1,4):
fn = file_name(c)
try:
photo = tk.PhotoImage(fn)
tk.Button(C, image = photo, width = "16", height = "16").grid(row = r,column = c)
except Exception as exception: