CustomTkinter
CustomTkinter copied to clipboard
Implement Toggleable Focus-Loss for CTkEntry and CTkTextbox on External Click
This commit introduces a new feature to the CTkEntry widget that allows it to lose focus when the user clicks outside of it. The functionality is designed to be toggleable, giving developers the flexibility to enable or disable this behavior based on their application's requirements.
Key Changes:
- Added a
focus_loss_outside_click
parameter to the__init__
method of the CTkEntry class, enabling the focus-loss feature by default. - Implemented
_get_root_window
method to traverse the widget hierarchy and find the root window, ensuring compatibility with various application structures. - Implemented
_on_root_click
method, which checks if a mouse click occurred outside the CTkEntry widget and shifts focus to the root window to effectively remove focus from the CTkEntry. - Implemented
_is_click_inside
method to determine if a given click event is within the bounds of the CTkEntry widget, aiding the focus management logic. - Adjusted
_create_bindings
method to include binding for root window clicks if not disabled byfocus_loss_outside_click
.
It will be great idea
Sometimes it can be really annoying, when entry widget always stays active. You should also add it to CTkTexbox.
i will take a look :-)
@JanPanthera this does not work for toplevel windows.