From d9ff3d998c9210e6900250fe260158a1dca6a5d7 Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Sun, 17 Jul 2022 20:34:54 +0200 Subject: [PATCH] fixed command function bug in CTkSwitch --- customtkinter/widgets/ctk_switch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/customtkinter/widgets/ctk_switch.py b/customtkinter/widgets/ctk_switch.py index de64448..f1de210 100644 --- a/customtkinter/widgets/ctk_switch.py +++ b/customtkinter/widgets/ctk_switch.py @@ -104,13 +104,13 @@ class CTkSwitch(CTkBaseClass): self.text_label.bind("", self.on_leave) self.text_label.bind("", self.toggle) - self.draw() # initial draw - self.set_cursor() - if self.variable is not None and self.variable != "": self.variable_callback_name = self.variable.trace_add("write", self.variable_callback) self.check_state = True if self.variable.get() == self.onvalue else False + self.draw() # initial draw + self.set_cursor() + def set_scaling(self, *args, **kwargs): super().set_scaling(*args, **kwargs) @@ -209,14 +209,14 @@ class CTkSwitch(CTkBaseClass): self.draw(no_color_updates=True) - if self.command is not None: - self.command() - if self.variable is not None: self.variable_callback_blocked = True self.variable.set(self.onvalue if self.check_state is True else self.offvalue) self.variable_callback_blocked = False + if self.command is not None: + self.command() + def select(self, from_variable_callback=False): if self.state is not tkinter.DISABLED or from_variable_callback: self.check_state = True