为导入gif时“找不到文件”特金特实验室

2024-05-04 05:49:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将gif导入Tkinter.标签. 我得到一个文件不存在的错误。我仔细检查了路径和文件名。你知道吗

下面是我收到的错误信息。你知道吗

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编程的新手。如果问题太琐碎,我道歉。你知道吗


Tags: nameinpyselfprojectinitmainline
1条回答
网友
1楼 · 发布于 2024-05-04 05:49:40

我也犯了同样的错误,我确信这条路也是正确的。事实上,它似乎每隔一次尝试就找到这个文件,代码非常相似。你知道吗

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:

相关问题 更多 >