【发布时间】:2020-12-13 15:29:33
【问题描述】:
***错误信息:
Traceback (most recent call last):
File "C:/Users/gurse/Desktop/Khanda/Khanda.py", line 3, in <module>
label = Label(x, image=PhotoImage(file=r"C:\Users\gurse\Desktop\Khanda"))
File "C:\Users\gurse\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4062, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\gurse\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4007, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "C:\Users\gurse\Desktop\Khanda": permission denied *****
我当前的代码:
from tkinter import *
x = Tk()
label = Label(x, image=PhotoImage(file=r"C:\Users\gurse\Desktop\Khanda"))
反斜杠变成了一个 Y,有 2 行。
【问题讨论】:
-
好吧。您的错误消息非常简单。 Python 无权打开您的文件。
-
路径为目录,无法打开。您需要提供图像文件的路径。但是,如果您提供了正确的图像路径,它将不会显示,因为它将被垃圾收集,并且您也没有在
label上调用任何布局函数。x.mainloop()也不见了。
标签: python tkinter photoimage