From 2964b39410705cdb10977bf22f226de6432c34b6 Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Tue, 4 Oct 2022 16:55:34 +0200 Subject: [PATCH] enhanced bind and unbind with double bind call on two tkinter widgets for some CTk widgets --- customtkinter/widgets/ctk_button.py | 16 ++++++++------ customtkinter/widgets/ctk_label.py | 18 +++++++++------- customtkinter/widgets/ctk_optionmenu.py | 16 ++++++++------ customtkinter/widgets/ctk_textbox.py | 21 ------------------- .../complex_example_new.py | 4 +++- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/customtkinter/widgets/ctk_button.py b/customtkinter/widgets/ctk_button.py index a8dc969..ec6ec1c 100644 --- a/customtkinter/widgets/ctk_button.py +++ b/customtkinter/widgets/ctk_button.py @@ -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) diff --git a/customtkinter/widgets/ctk_label.py b/customtkinter/widgets/ctk_label.py index ff4f2d9..5c79084 100644 --- a/customtkinter/widgets/ctk_label.py +++ b/customtkinter/widgets/ctk_label.py @@ -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) diff --git a/customtkinter/widgets/ctk_optionmenu.py b/customtkinter/widgets/ctk_optionmenu.py index c803219..bafafe6 100644 --- a/customtkinter/widgets/ctk_optionmenu.py +++ b/customtkinter/widgets/ctk_optionmenu.py @@ -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) diff --git a/customtkinter/widgets/ctk_textbox.py b/customtkinter/widgets/ctk_textbox.py index 87648ba..7034cb2 100644 --- a/customtkinter/widgets/ctk_textbox.py +++ b/customtkinter/widgets/ctk_textbox.py @@ -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) diff --git a/test/manual_integration_tests/complex_example_new.py b/test/manual_integration_tests/complex_example_new.py index ec6f7c2..3b293bc 100644 --- a/test/manual_integration_tests/complex_example_new.py +++ b/test/manual_integration_tests/complex_example_new.py @@ -127,6 +127,9 @@ class App(customtkinter.CTk): self.progressbar_1.configure(mode="indeterminnate") self.progressbar_1.start() + r = self.logo_label.bind("", 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()