enhanced bind and unbind with double bind call on two tkinter widgets for some CTk widgets

This commit is contained in:
Tom Schimansky 2022-10-04 16:55:34 +02:00
parent 8b85225133
commit 2964b39410
5 changed files with 34 additions and 41 deletions

View File

@ -409,10 +409,14 @@ class CTkButton(CTkBaseClass):
self._command()
def bind(self, sequence=None, command=None, add=None):
""" called on the tkinter.Canvas """
return self._canvas.bind(sequence, command, add)
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)
label_bind_return = self._text_label.bind(sequence, command, add)
return canvas_bind_return + " + " + label_bind_return
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def unbind(self, sequence: str, funcid: str = None):
""" called on the tkinter.Label and tkinter.Canvas """
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)

View File

@ -1,5 +1,5 @@
import tkinter
from typing import Union, Tuple
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
@ -182,10 +182,14 @@ class CTkLabel(CTkBaseClass):
else:
return super().cget(attribute_name) # cget of CTkBaseClass
def bind(self, sequence=None, command=None, add=None):
""" called on the tkinter.Label """
return self._text_label.bind(sequence, command, add)
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)
label_bind_return = self._text_label.bind(sequence, command, add)
return canvas_bind_return + " + " + label_bind_return
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Label """
return self._text_label.unbind(sequence, funcid)
def unbind(self, sequence: str, funcid: str = None):
""" called on the tkinter.Label and tkinter.Canvas """
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)

View File

@ -358,10 +358,14 @@ class CTkOptionMenu(CTkBaseClass):
if self._state is not tkinter.DISABLED and len(self._values) > 0:
self._open_dropdown_menu()
def bind(self, sequence=None, command=None, add=None):
""" called on the tkinter.Label """
return self._text_label.bind(sequence, command, add)
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)
label_bind_return = self._text_label.bind(sequence, command, add)
return canvas_bind_return + " + " + label_bind_return
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Label """
return self._text_label.unbind(sequence, funcid)
def unbind(self, sequence: str, funcid: str = None):
""" called on the tkinter.Label and tkinter.Canvas """
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)

View File

@ -210,24 +210,3 @@ class CTkTextbox(CTkBaseClass):
def get(self, index1, index2=None):
return self._textbox.get(index1, index2)
def yview(self, *args):
return self._textbox.yview(*args)
def xview(self, *args):
return self._textbox.xview(*args)
def focus(self):
return self._textbox.focus()
def tag_add(self, *args, **kwargs):
return self._textbox.tag_add(*args, **kwargs)
def tag_config(self, *args, **kwargs):
return self._textbox.tag_config(*args, **kwargs)
def tag_configure(self, *args, **kwargs):
return self._textbox.tag_configure(*args, **kwargs)
def tag_remove(self, *args, **kwargs):
return self._textbox.tag_remove(*args, **kwargs)

View File

@ -127,6 +127,9 @@ class App(customtkinter.CTk):
self.progressbar_1.configure(mode="indeterminnate")
self.progressbar_1.start()
r = self.logo_label.bind("<Button-1>", lambda e: print("click"))
print(r, type(r))
def open_input_dialog(self):
dialog = customtkinter.CTkInputDialog(master=self, text="Type in a number:", title="CTkInputDialog")
print("CTkInputDialog:", dialog.get_input())
@ -142,7 +145,6 @@ class App(customtkinter.CTk):
def sidebar_button_callback(self):
print("sidebar_button click")
self.entry.delete(0, tkinter.END)
print(self.textbox.get("0.0", "end"))
def on_closing(self, event=0):
self.destroy()