【发布时间】:2020-08-19 20:08:52
【问题描述】:
我正在用 python 做一个小 GUI,我想添加一个带有图像的按钮。所以我正在关注这里所说的:https://www.geeksforgeeks.org/python-add-image-on-a-tkinter-button/
它给出了:
downimage = PhotoImage(file = "Downloadimage.png")
Dowloadbutton = Button(window, image=downimage, font=("Source Code Pro Light", 20), bg='black', fg='lime', command=start)
Dowloadbutton.pack()
正如链接中所说。但奇迹发生了:
Traceback (most recent call last):
File "Keylogger.pyw", line 28, in <module>
downimage = PhotoImage(file = "Downloadimage.png")
File "C:\Users\Elève\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Elève\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: CRC check failed
第 28 行对应于downimage = PhotoImage(file = "Downloadimage.png")。
其他所有内容都已打包并出现,但我的按钮没有并给了我该错误。
我不知道这是什么意思,当我尝试在互联网上搜索时,出现了很多与 tkinter 无关的结果,这似乎不是一个常见但仍然已知的错误。
(我正在使用 python 和 tkinter 的最新版本)
如果你能帮助我,真的非常感谢你!祝你有美好的一天;)
【问题讨论】:
标签: python python-3.x button tkinter