fixed command function bug in CTkSwitch

This commit is contained in:
Tom Schimansky 2022-07-17 20:34:54 +02:00
parent 6a43dfd9bf
commit d9ff3d998c

View File

@ -104,13 +104,13 @@ class CTkSwitch(CTkBaseClass):
self.text_label.bind("<Leave>", self.on_leave)
self.text_label.bind("<Button-1>", 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