diff --git a/customtkinter/windows/widgets/ctk_button.py b/customtkinter/windows/widgets/ctk_button.py index 8dec387..45ed025 100644 --- a/customtkinter/windows/widgets/ctk_button.py +++ b/customtkinter/windows/widgets/ctk_button.py @@ -107,13 +107,31 @@ class CTkButton(CTkBaseClass): def _create_bindings(self, sequence: Optional[str] = None): """ set necessary bindings for functionality of widget, will overwrite other bindings """ + if sequence is None or sequence == "": self._canvas.bind("", self._on_enter) + + if self._text_label is not None: + self._text_label.bind("", self._on_enter) + if self._image_label is not None: + self._image_label.bind("", self._on_enter) + if sequence is None or sequence == "": self._canvas.bind("", self._on_leave) + + if self._text_label is not None: + self._text_label.bind("", self._on_leave) + if self._image_label is not None: + self._image_label.bind("", self._on_leave) + if sequence is None or sequence == "": self._canvas.bind("", self._clicked) + if self._text_label is not None: + self._text_label.bind("", self._clicked) + if self._image_label is not None: + self._image_label.bind("", self._clicked) + def _set_scaling(self, *args, **kwargs): super()._set_scaling(*args, **kwargs) @@ -541,7 +559,11 @@ class CTkButton(CTkBaseClass): if not (add == "+" or add is True): raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") self._canvas.bind(sequence, command, add=True) - self._text_label.bind(sequence, command, add=True) + + if self._text_label is not None: + self._text_label.bind(sequence, command, add=True) + if self._image_label is not None: + self._image_label.bind(sequence, command, add=True) def unbind(self, sequence: str = None, funcid: str = None): """ called on the tkinter.Label and tkinter.Canvas """ @@ -549,7 +571,12 @@ class CTkButton(CTkBaseClass): raise ValueError("'funcid' argument can only be None, because there is a bug in" + " tkinter and its not clear whether the internal callbacks will be unbinded or not") self._canvas.unbind(sequence, None) - self._text_label.unbind(sequence, None) + + if self._text_label is not None: + self._text_label.unbind(sequence, None) + if self._image_label is not None: + self._image_label.unbind(sequence, None) + self._create_bindings(sequence=sequence) # restore internal callbacks for sequence def focus(self):