2022-03-08 17:03:47 +03:00
|
|
|
import tkinter
|
|
|
|
import sys
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
from .ctk_canvas import CTkCanvas
|
2022-05-17 22:44:59 +03:00
|
|
|
from ..theme_manager import ThemeManager
|
|
|
|
from ..settings import Settings
|
|
|
|
from ..draw_engine import DrawEngine
|
2022-04-20 23:50:57 +03:00
|
|
|
from .widget_base_class import CTkBaseClass
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
class CTkSwitch(CTkBaseClass):
|
2022-03-08 17:03:47 +03:00
|
|
|
def __init__(self, *args,
|
|
|
|
text="CTkSwitch",
|
|
|
|
text_font="default_theme",
|
|
|
|
text_color="default_theme",
|
2022-05-22 18:11:15 +03:00
|
|
|
text_color_disabled="default_theme",
|
2022-03-08 17:03:47 +03:00
|
|
|
bg_color=None,
|
|
|
|
border_color=None,
|
|
|
|
fg_color="default_theme",
|
|
|
|
progress_color="default_theme",
|
|
|
|
button_color="default_theme",
|
|
|
|
button_hover_color="default_theme",
|
|
|
|
width=36,
|
|
|
|
height=18,
|
|
|
|
corner_radius="default_theme",
|
2022-03-10 04:12:30 +03:00
|
|
|
# button_corner_radius="default_theme",
|
2022-03-08 17:03:47 +03:00
|
|
|
border_width="default_theme",
|
|
|
|
button_length="default_theme",
|
|
|
|
command=None,
|
|
|
|
onvalue=1,
|
|
|
|
offvalue=0,
|
|
|
|
variable=None,
|
|
|
|
textvariable=None,
|
2022-05-22 18:11:15 +03:00
|
|
|
state=tkinter.NORMAL,
|
2022-03-08 17:03:47 +03:00
|
|
|
**kwargs):
|
2022-04-20 23:50:57 +03:00
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
2022-04-20 23:50:57 +03:00
|
|
|
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
|
|
|
|
|
|
|
|
# color
|
2022-03-08 17:03:47 +03:00
|
|
|
self.border_color = border_color
|
2022-05-17 22:44:59 +03:00
|
|
|
self.fg_color = ThemeManager.theme["color"]["switch"] if fg_color == "default_theme" else fg_color
|
|
|
|
self.progress_color = ThemeManager.theme["color"]["switch_progress"] if progress_color == "default_theme" else progress_color
|
|
|
|
self.button_color = ThemeManager.theme["color"]["switch_button"] if button_color == "default_theme" else button_color
|
|
|
|
self.button_hover_color = ThemeManager.theme["color"]["switch_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
|
|
|
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
2022-06-30 16:53:32 +03:00
|
|
|
self.text_color_disabled = ThemeManager.theme["color"]["text_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# text
|
2022-03-08 17:03:47 +03:00
|
|
|
self.text = text
|
2022-04-20 23:50:57 +03:00
|
|
|
self.text_label = None
|
2022-05-17 22:44:59 +03:00
|
|
|
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
2022-04-20 23:50:57 +03:00
|
|
|
|
|
|
|
# shape
|
2022-05-17 22:44:59 +03:00
|
|
|
self.corner_radius = ThemeManager.theme["shape"]["switch_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
|
|
|
# self.button_corner_radius = ThemeManager.theme["shape"]["switch_button_corner_radius"] if button_corner_radius == "default_theme" else button_corner_radius
|
|
|
|
self.border_width = ThemeManager.theme["shape"]["switch_border_width"] if border_width == "default_theme" else border_width
|
|
|
|
self.button_length = ThemeManager.theme["shape"]["switch_button_length"] if button_length == "default_theme" else button_length
|
2022-03-08 17:03:47 +03:00
|
|
|
self.hover_state = False
|
|
|
|
self.check_state = False # True if switch is activated
|
2022-05-22 18:11:15 +03:00
|
|
|
self.state = state
|
2022-03-08 17:03:47 +03:00
|
|
|
self.onvalue = onvalue
|
|
|
|
self.offvalue = offvalue
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# callback and control variables
|
2022-07-05 15:39:12 +03:00
|
|
|
self.command = command
|
2022-03-08 17:03:47 +03:00
|
|
|
self.variable: tkinter.Variable = variable
|
|
|
|
self.variable_callback_blocked = False
|
|
|
|
self.variable_callback_name = None
|
|
|
|
self.textvariable = textvariable
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# configure grid system (3x1)
|
2022-03-08 17:03:47 +03:00
|
|
|
self.grid_columnconfigure(0, weight=1)
|
2022-05-02 00:29:14 +03:00
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self.apply_widget_scaling(6))
|
2022-03-08 17:03:47 +03:00
|
|
|
self.grid_columnconfigure(2, weight=0)
|
|
|
|
|
2022-04-21 21:30:46 +03:00
|
|
|
self.bg_canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
2022-05-31 23:32:21 +03:00
|
|
|
width=self.apply_widget_scaling(self._current_width),
|
|
|
|
height=self.apply_widget_scaling(self._current_height))
|
2022-04-21 21:30:46 +03:00
|
|
|
self.bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
self.canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
2022-05-31 23:32:21 +03:00
|
|
|
width=self.apply_widget_scaling(self._current_width),
|
|
|
|
height=self.apply_widget_scaling(self._current_height))
|
2022-03-08 17:03:47 +03:00
|
|
|
self.canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=1, sticky="nswe")
|
2022-05-22 01:02:45 +03:00
|
|
|
self.draw_engine = DrawEngine(self.canvas)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
self.canvas.bind("<Enter>", self.on_enter)
|
|
|
|
self.canvas.bind("<Leave>", self.on_leave)
|
|
|
|
self.canvas.bind("<Button-1>", self.toggle)
|
|
|
|
|
2022-07-02 01:54:21 +03:00
|
|
|
self.text_label = tkinter.Label(master=self,
|
|
|
|
bd=0,
|
|
|
|
text=self.text,
|
|
|
|
justify=tkinter.LEFT,
|
|
|
|
font=self.apply_font_scaling(self.text_font),
|
|
|
|
textvariable=self.textvariable)
|
|
|
|
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
|
|
|
self.text_label["anchor"] = "w"
|
|
|
|
|
|
|
|
self.text_label.bind("<Enter>", self.on_enter)
|
|
|
|
self.text_label.bind("<Leave>", self.on_leave)
|
|
|
|
self.text_label.bind("<Button-1>", self.toggle)
|
|
|
|
|
2022-07-05 15:39:12 +03:00
|
|
|
if self.variable is not None and self.variable != "":
|
2022-03-08 17:03:47 +03:00
|
|
|
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
2022-07-05 15:39:12 +03:00
|
|
|
self.check_state = True if self.variable.get() == self.onvalue else False
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-17 21:34:54 +03:00
|
|
|
self.draw() # initial draw
|
|
|
|
self.set_cursor()
|
|
|
|
|
2022-05-02 00:29:14 +03:00
|
|
|
def set_scaling(self, *args, **kwargs):
|
|
|
|
super().set_scaling(*args, **kwargs)
|
|
|
|
|
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self.apply_widget_scaling(6))
|
|
|
|
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
self.bg_canvas.configure(width=self.apply_widget_scaling(self._desired_width), height=self.apply_widget_scaling(self._desired_height))
|
|
|
|
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width), height=self.apply_widget_scaling(self._desired_height))
|
2022-05-02 00:29:14 +03:00
|
|
|
self.draw()
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
def destroy(self):
|
|
|
|
# remove variable_callback from variable callbacks if variable exists
|
|
|
|
if self.variable is not None:
|
|
|
|
self.variable.trace_remove("write", self.variable_callback_name)
|
|
|
|
|
|
|
|
super().destroy()
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
def set_cursor(self):
|
2022-05-17 22:44:59 +03:00
|
|
|
if Settings.cursor_manipulation_enabled:
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.state == tkinter.DISABLED:
|
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
|
|
|
self.canvas.configure(cursor="arrow")
|
2022-05-30 14:39:10 +03:00
|
|
|
if self.text_label is not None:
|
|
|
|
self.text_label.configure(cursor="arrow")
|
2022-05-22 18:11:15 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
|
|
|
self.canvas.configure(cursor="arrow")
|
2022-05-30 14:39:10 +03:00
|
|
|
if self.text_label is not None:
|
|
|
|
self.text_label.configure(cursor="arrow")
|
|
|
|
|
|
|
|
elif self.state == tkinter.NORMAL:
|
2022-05-22 18:11:15 +03:00
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
|
|
|
self.canvas.configure(cursor="pointinghand")
|
2022-05-30 14:39:10 +03:00
|
|
|
if self.text_label is not None:
|
|
|
|
self.text_label.configure(cursor="pointinghand")
|
2022-05-22 18:11:15 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
|
|
|
self.canvas.configure(cursor="hand2")
|
2022-05-30 14:39:10 +03:00
|
|
|
if self.text_label is not None:
|
|
|
|
self.text_label.configure(cursor="hand2")
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
def draw(self, no_color_updates=False):
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if self.check_state is True:
|
2022-05-31 23:32:21 +03:00
|
|
|
requires_recoloring = self.draw_engine.draw_rounded_slider_with_border_and_button(self.apply_widget_scaling(self._current_width),
|
|
|
|
self.apply_widget_scaling(self._current_height),
|
2022-05-02 00:29:14 +03:00
|
|
|
self.apply_widget_scaling(self.corner_radius),
|
|
|
|
self.apply_widget_scaling(self.border_width),
|
|
|
|
self.apply_widget_scaling(self.button_length),
|
|
|
|
self.apply_widget_scaling(self.corner_radius),
|
|
|
|
1, "w")
|
2022-03-08 17:03:47 +03:00
|
|
|
else:
|
2022-05-31 23:32:21 +03:00
|
|
|
requires_recoloring = self.draw_engine.draw_rounded_slider_with_border_and_button(self.apply_widget_scaling(self._current_width),
|
|
|
|
self.apply_widget_scaling(self._current_height),
|
2022-05-02 00:29:14 +03:00
|
|
|
self.apply_widget_scaling(self.corner_radius),
|
|
|
|
self.apply_widget_scaling(self.border_width),
|
|
|
|
self.apply_widget_scaling(self.button_length),
|
|
|
|
self.apply_widget_scaling(self.corner_radius),
|
2022-04-21 19:34:58 +03:00
|
|
|
0, "w")
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
if no_color_updates is False or requires_recoloring:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.bg_canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
|
|
|
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if self.border_color is None:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("border_parts", fill=ThemeManager.single_color(self.bg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
else:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("border_parts", fill=ThemeManager.single_color(self.border_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.border_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("inner_parts", fill=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if self.progress_color is None:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
else:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self.progress_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.progress_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.state == tkinter.DISABLED:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.text_label.configure(fg=(ThemeManager.single_color(self.text_color_disabled, self._appearance_mode)))
|
2022-05-22 18:11:15 +03:00
|
|
|
else:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.text_label.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
2022-05-22 18:11:15 +03:00
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
self.text_label.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
def toggle(self, event=None):
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.state is not tkinter.DISABLED:
|
|
|
|
if self.check_state is True:
|
|
|
|
self.check_state = False
|
|
|
|
else:
|
|
|
|
self.check_state = True
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
self.draw(no_color_updates=True)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
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
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-17 21:34:54 +03:00
|
|
|
if self.command is not None:
|
|
|
|
self.command()
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
def select(self, from_variable_callback=False):
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.state is not tkinter.DISABLED or from_variable_callback:
|
|
|
|
self.check_state = True
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
self.draw(no_color_updates=True)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.variable is not None and not from_variable_callback:
|
|
|
|
self.variable_callback_blocked = True
|
|
|
|
self.variable.set(self.onvalue)
|
|
|
|
self.variable_callback_blocked = False
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-05 15:39:12 +03:00
|
|
|
if self.command is not None:
|
|
|
|
self.command()
|
2022-05-31 23:32:21 +03:00
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
def deselect(self, from_variable_callback=False):
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.state is not tkinter.DISABLED or from_variable_callback:
|
|
|
|
self.check_state = False
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
self.draw(no_color_updates=True)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
if self.variable is not None and not from_variable_callback:
|
|
|
|
self.variable_callback_blocked = True
|
|
|
|
self.variable.set(self.offvalue)
|
|
|
|
self.variable_callback_blocked = False
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-05 15:39:12 +03:00
|
|
|
if self.command is not None:
|
|
|
|
self.command()
|
2022-05-31 23:32:21 +03:00
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
def get(self):
|
|
|
|
return self.onvalue if self.check_state is True else self.offvalue
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
def on_enter(self, event=0):
|
|
|
|
self.hover_state = True
|
2022-05-22 18:11:15 +03:00
|
|
|
|
|
|
|
if self.state is not tkinter.DISABLED:
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
def on_leave(self, event=0):
|
|
|
|
self.hover_state = False
|
2022-05-31 23:32:21 +03:00
|
|
|
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
def variable_callback(self, var_name, index, mode):
|
|
|
|
if not self.variable_callback_blocked:
|
|
|
|
if self.variable.get() == self.onvalue:
|
|
|
|
self.select(from_variable_callback=True)
|
|
|
|
elif self.variable.get() == self.offvalue:
|
|
|
|
self.deselect(from_variable_callback=True)
|
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
def configure(self, require_redraw=False, **kwargs):
|
2022-07-02 01:54:21 +03:00
|
|
|
if "text" in kwargs:
|
|
|
|
self.text = kwargs.pop("text")
|
|
|
|
self.text_label.configure(text=self.text)
|
|
|
|
|
2022-08-16 15:05:15 +03:00
|
|
|
if "text_font" in kwargs:
|
|
|
|
self.text_font = kwargs.pop("text_font")
|
|
|
|
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
|
|
|
|
2022-05-22 18:11:15 +03:00
|
|
|
if "state" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.state = kwargs.pop("state")
|
2022-05-22 18:11:15 +03:00
|
|
|
self.set_cursor()
|
|
|
|
require_redraw = True
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
if "fg_color" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.fg_color = kwargs.pop("fg_color")
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "progress_color" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
new_progress_color = kwargs.pop("progress_color")
|
|
|
|
if new_progress_color is None:
|
2022-03-08 17:03:47 +03:00
|
|
|
self.progress_color = self.fg_color
|
|
|
|
else:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.progress_color = new_progress_color
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "button_color" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.button_color = kwargs.pop("button_color")
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "button_hover_color" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.button_hover_color = kwargs.pop("button_hover_color")
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "border_color" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.border_color = kwargs.pop("border_color")
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "border_width" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.border_width = kwargs.pop("border_width")
|
2022-03-08 17:03:47 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "command" in kwargs:
|
2022-07-05 15:39:12 +03:00
|
|
|
self.command = kwargs.pop("command")
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if "textvariable" in kwargs:
|
2022-07-02 01:54:21 +03:00
|
|
|
self.textvariable = kwargs.pop("textvariable")
|
|
|
|
self.text_label.configure(textvariable=self.textvariable)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if "variable" in kwargs:
|
2022-07-05 15:39:12 +03:00
|
|
|
if self.variable is not None and self.variable != "":
|
2022-03-08 17:03:47 +03:00
|
|
|
self.variable.trace_remove("write", self.variable_callback_name)
|
|
|
|
|
2022-07-02 01:54:21 +03:00
|
|
|
self.variable = kwargs.pop("variable")
|
2022-03-08 17:03:47 +03:00
|
|
|
|
|
|
|
if self.variable is not None and self.variable != "":
|
|
|
|
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
2022-07-05 15:39:12 +03:00
|
|
|
self.check_state = True if self.variable.get() == self.onvalue else False
|
|
|
|
require_redraw = True
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
super().configure(require_redraw=require_redraw, **kwargs)
|