From f18ac0c81a981d5d57487bb8e86eaa211fc8f66f Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Fri, 11 Nov 2022 00:32:52 +0100 Subject: [PATCH] added .invoke() method to button #605 --- CHANGELOG.md | 5 +++-- customtkinter/windows/widgets/ctk_button.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3490b3d..0a150d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ ToDo: - add new button attributes to wiki - cursor configuring - overwrite winfo methods - - renew input dialog ## Unreleased - 2022-10-2 ### Added @@ -22,15 +21,17 @@ ToDo: - Added 'anchor' option to CTkOptionMenu and 'justify' option to CTkComboBox - Added CTkFont class - Added CTkImage class to replace PIL.ImageTk.PhotoImage, supports scaling and two images for appearance mode, supports configuring - + - Added missing configure options for multiple widgets ### Changed + - Changed value for transparent colors (same as background) from None to 'transparent' - Changed 'text_font' attribute to 'font' in all widgets, changed 'dropdown_text_font' to 'dropdown_font' - Changed 'dropdown_color' attribute to 'dropdown_fg_color' for combobox, optionmenu - Changed 'orient' attribute of CTkProgressBar and CTkSlider to 'orientation' - Width and height attributes of CTkCheckBox, CTkRadioButton, CTkSwitch now describe the outer dimensions of the whole widget. The button/switch size is described by separate attributes like checkbox_width, checkbox_height - font attribute must be tuple or CTkFont now, all size values are measured in pixel now - Changed dictionary key 'window_bg_color' to 'window' in theme files + - CTkInputDialog attributes completely changed ### Removed - Removed setter and getter functions like set_text in CTkButton diff --git a/customtkinter/windows/widgets/ctk_button.py b/customtkinter/windows/widgets/ctk_button.py index e9c6abc..3692f79 100644 --- a/customtkinter/windows/widgets/ctk_button.py +++ b/customtkinter/windows/widgets/ctk_button.py @@ -513,16 +513,22 @@ class CTkButton(CTkBaseClass): self._on_enter() def _clicked(self, event=None): - if self._command is not None: - if self._state != tkinter.DISABLED: + if self._state != tkinter.DISABLED: - # click animation: change color with .on_leave() and back to normal after 100ms with click_animation() - self._on_leave() - self._click_animation_running = True - self.after(100, self._click_animation) + # click animation: change color with .on_leave() and back to normal after 100ms with click_animation() + self._on_leave() + self._click_animation_running = True + self.after(100, self._click_animation) + if self._command is not None: self._command() + def invoke(self): + """ calls command function if button is not disabled """ + if self._state != tkinter.DISABLED: + if self._command is not None: + return self._command() + def bind(self, sequence: str = None, command: Callable = None, add: str = None) -> str: """ called on the tkinter.Label and tkinter.Canvas """ canvas_bind_return = self._canvas.bind(sequence, command, add)