CustomTkinter
CustomTkinter copied to clipboard
How to know if a given widget is focussed?
import customtkinter as tk
def check_focus(widget):
widget.focus_set()
root.update()
focused_widget = root.focus_get()
if focused_widget.winfo_name() == widget.winfo_name():
print(f"The widget is focused.")
else:
print(f"The widget is not focused.")
root = tk.CTk()
entry = tk.CTkEntry(root)
button = tk.CTkButton(root, text="Check Focus", command=lambda: check_focus(entry))
entry.pack(padx=10, pady=10)
button.pack(pady=10)
root.mainloop()`
Even if i have focussed on entry widget, i get false. I printed them when I have widget selected and got output: focussud- .!ctkentry.!entry widget- .!ctkentry
They both are same still printing different values. How, help?