Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSchimansky committed Dec 25, 2022
1 parent 5bbd72b commit 1396a7e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions customtkinter/windows/widgets/ctk_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,31 @@ def __init__(self,

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 == "<Enter>":
self._canvas.bind("<Enter>", self._on_enter)

if self._text_label is not None:
self._text_label.bind("<Enter>", self._on_enter)
if self._image_label is not None:
self._image_label.bind("<Enter>", self._on_enter)

if sequence is None or sequence == "<Leave>":
self._canvas.bind("<Leave>", self._on_leave)

if self._text_label is not None:
self._text_label.bind("<Leave>", self._on_leave)
if self._image_label is not None:
self._image_label.bind("<Leave>", self._on_leave)

if sequence is None or sequence == "<Button-1>":
self._canvas.bind("<Button-1>", self._clicked)

if self._text_label is not None:
self._text_label.bind("<Button-1>", self._clicked)
if self._image_label is not None:
self._image_label.bind("<Button-1>", self._clicked)

def _set_scaling(self, *args, **kwargs):
super()._set_scaling(*args, **kwargs)

Expand Down Expand Up @@ -541,15 +559,24 @@ def bind(self, sequence: str = None, command: Callable = None, add: Union[str, b
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 """
if funcid is not None:
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):
Expand Down

0 comments on commit 1396a7e

Please sign in to comment.