root.focus_get() 不能检测焦点是否在自定义 Tkinter 输入框上。
作者: VermillionDev创建于 2022年11月10日更新于 2026年6月24日
标签bug
import customtkinter
from tkinter import *
def test(event):
if root.focus_get() == custom_entry:
print("custom_entry")
elif root.focus_get() == ttk_entry:
print("ttk_entry")
root = customtkinter.CTk()
custom_entry = customtkinter.CTkEntry(root) # CTkEntry
custom_entry.pack()
ttk_entry = Entry(root) # ttk_entry
ttk_entry.pack()
root.bind("<Return>", test)
root.mainloop()当我点击ttk entry并按下Enter键时,它会打印出"ttk_entry"。
内容来源: TomSchimansky/CustomTkinter