【发布时间】:2022-12-20 23:29:47
【问题描述】:
我正在使用 customtkinter 库创建一个按钮。该按钮用于关闭程序。
下面是按钮的定义:
exit_button = ctk.CTkButton(master=main_menu_frame,
text="Exit",
command=root.destroy,
corner_radius=0,
width=WIDTH-40-260,
height=60,
text_font=("century gothic", 16),
)
如您所见,该命令等于 root.destroy。当我点击这个按钮时它真的关闭了窗口,但它也给出了一个例外。 这是例外:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\customtkinter\customtkinter_button.py", line 501, in clicked
self.on_leave()
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\customtkinter\customtkinter_button.py", line 485, in on_leave
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2903, in itemconfigure
return self._configure(('itemconfigure', tagOrId), cnf, kw)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1636, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!ctkframe2.!ctkbutton3.!canvas"
这是一些要测试的代码:
import tkinter as tk
import customtkinter as ctk
root = tk.Tk()
btn = ctk.CTkButton(master=root, text="EXIT", command=root.destroy).pack()
root.mainloop()
使用此代码,我得到了相同的异常。
【问题讨论】:
-
请提供minimal reproducible example。该错误是由您对
on_leave的定义引起的,但您没有提供该定义。 -
你什么意思?我没有在我的代码中的任何地方使用过
on_leave。 -
@BryanOakley 该方法似乎是在位于
site-packages的某个模块(customtkinter)中定义的,这意味着它可能是通过pip安装的 -
我通过 pip 安装了自定义修补程序
-
这是
customtkinter库中的一个错误,按钮在它被销毁后被修改,现在已修复,上面的代码应该适用于 1.8 及更高版本!
标签: python tkinter customtkinter