This commit is contained in:
Tom Schimansky 2022-12-25 21:03:33 +01:00
parent 5bbd72b5dc
commit 1396a7e484

View File

@ -107,13 +107,31 @@ class CTkButton(CTkBaseClass):
def _create_bindings(self, sequence: Optional[str] = None): def _create_bindings(self, sequence: Optional[str] = None):
""" set necessary bindings for functionality of widget, will overwrite other bindings """ """ set necessary bindings for functionality of widget, will overwrite other bindings """
if sequence is None or sequence == "<Enter>": if sequence is None or sequence == "<Enter>":
self._canvas.bind("<Enter>", self._on_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>": if sequence is None or sequence == "<Leave>":
self._canvas.bind("<Leave>", self._on_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>": if sequence is None or sequence == "<Button-1>":
self._canvas.bind("<Button-1>", self._clicked) 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): def _set_scaling(self, *args, **kwargs):
super()._set_scaling(*args, **kwargs) super()._set_scaling(*args, **kwargs)
@ -541,7 +559,11 @@ class CTkButton(CTkBaseClass):
if not (add == "+" or add is True): if not (add == "+" or add is True):
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")
self._canvas.bind(sequence, command, add=True) 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): def unbind(self, sequence: str = None, funcid: str = None):
""" called on the tkinter.Label and tkinter.Canvas """ """ 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" + 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") " tkinter and its not clear whether the internal callbacks will be unbinded or not")
self._canvas.unbind(sequence, None) 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 self._create_bindings(sequence=sequence) # restore internal callbacks for sequence
def focus(self): def focus(self):