-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Toggleable Focus-Loss for CTkEntry and CTkTextbox on External Click #2251
base: master
Are you sure you want to change the base?
Conversation
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 by `focus_loss_outside_click`.
It will be great idea |
This commit addresses a bug where the CTkEntry widget was unable to lose focus when clicked outside. The `_on_root_click` method has been updated to only set the focus to the root window if the CTkEntry widget currently has the focus. This prevents the focus from being set to the root window when clicking on another widget that should receive the focus. Exception handling has also been improved for better error resilience.
This reverts commit d9dc57a.
This commit addresses a bug where the CTkEntry widget was unable to lose focus when clicked outside. The `_on_root_click` method has been updated to only set the focus to the root window if the CTkEntry widget currently has the focus. This prevents the focus from being set to the root window when clicking on another widget that should receive the focus. Exception handling has also been improved for better error resilience.
Sometimes it can be really annoying, when entry widget always stays active. You should also add it to CTkTexbox. |
i will take a look :-) |
This commit introduces a new feature to the CTkTextbox 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 CTkTextbox 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 CTkTextbox widget and shifts focus to the root window to effectively remove focus from the CTkTextbox . - Implemented `_is_click_inside` method to determine if a given click event is within the bounds of the CTkTextbox widget, aiding the focus management logic. - Adjusted `_create_bindings` method to include binding for root window clicks if not disabled by `focus_loss_outside_click`.
- Created a standalone function `handle_root_click` that encapsulates the logic for handling root window and click events. - This function takes a widget and an event as parameters, and an optional specific widget to check for focus. - Implemented this function in the `CTkEntry` and 'CtkTextbox' class, creating a new method `on_root_click` that calls `handle_root_click`. - Bound the root click event to the `on_root_click` method in the `CTkEntry` and 'CtkTextbox' class. - This change allows for better code reusability and separation of concerns.
return widget | ||
|
||
|
||
def handle_root_click(widget, event, specific_widget=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That method was needed a long time ago. Since the beginning.
@@ -20,3 +20,39 @@ def check_kwargs_empty(kwargs_dict, raise_error=False) -> bool: | |||
return True | |||
else: | |||
return False | |||
|
|||
|
|||
def get_root_window(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same goes for this method
… method in the `CTkTabview` class and the addition of code to update the `_current_name` attribute. These changes ensure that the tab renaming process is more efficient and that the connection to the frame is maintained even when a tab is renamed. Changes: 1. The renaming method in the `CTkTabview` class has been altered. Instead of removing the old name from the `_name_list` and appending the new name at the end, the new name now replaces the old name at the same index in the `_name_list`. This change makes the renaming process more efficient. 2. Code has been added to update the `_current_name` attribute if the old name matches the current name. This is a crucial change as it ensures that the connection to the frame is not lost when a tab is renamed.
@JanPanthera this does not work for toplevel windows. |
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:
focus_loss_outside_click
parameter to the__init__
method of the CTkEntry class, enabling the focus-loss feature by default._get_root_window
method to traverse the widget hierarchy and find the root window, ensuring compatibility with various application structures._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._is_click_inside
method to determine if a given click event is within the bounds of the CTkEntry widget, aiding the focus management logic._create_bindings
method to include binding for root window clicks if not disabled byfocus_loss_outside_click
.