2021-08-25 18:02:16 +03:00
|
|
|
import tkinter
|
|
|
|
import sys
|
2022-10-02 04:23:10 +03:00
|
|
|
from typing import Union, Tuple, Callable
|
2021-08-25 18:02:16 +03:00
|
|
|
|
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
|
2021-08-25 18:02:16 +03:00
|
|
|
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
class CTkCheckBox(CTkBaseClass):
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
|
|
|
Checkbox with rounded corners, border, variable support and hover effect.
|
|
|
|
For detailed information check out the documentation.
|
|
|
|
"""
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-06 16:53:52 +03:00
|
|
|
def __init__(self,
|
|
|
|
master: any = None,
|
2022-10-03 01:33:06 +03:00
|
|
|
width: int = 24,
|
|
|
|
height: int = 24,
|
|
|
|
corner_radius: Union[int, str] = "default_theme",
|
|
|
|
border_width: Union[int, str] = "default_theme",
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
bg_color: Union[str, Tuple[str, str], None] = None,
|
|
|
|
fg_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
hover_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
border_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
checkmark_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
text_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
text_color_disabled: Union[str, Tuple[str, str]] = "default_theme",
|
2022-10-03 01:33:06 +03:00
|
|
|
|
|
|
|
text: str = "CTkCheckBox",
|
|
|
|
font: any = "default_theme",
|
|
|
|
textvariable: tkinter.Variable = None,
|
|
|
|
state: str = tkinter.NORMAL,
|
2022-10-02 04:23:10 +03:00
|
|
|
hover: bool = True,
|
|
|
|
command: Callable = None,
|
|
|
|
onvalue: Union[int, str] = 1,
|
|
|
|
offvalue: Union[int, str] = 0,
|
|
|
|
variable: tkinter.Variable = None,
|
2022-01-16 18:54:21 +03:00
|
|
|
**kwargs):
|
2022-04-20 23:50:57 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
2022-10-06 16:53:52 +03:00
|
|
|
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
|
2022-04-20 23:50:57 +03:00
|
|
|
|
|
|
|
# color
|
2022-10-02 04:23:10 +03:00
|
|
|
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
|
|
|
self._hover_color = ThemeManager.theme["color"]["button_hover"] if hover_color == "default_theme" else hover_color
|
|
|
|
self._border_color = ThemeManager.theme["color"]["checkbox_border"] if border_color == "default_theme" else border_color
|
|
|
|
self._checkmark_color = ThemeManager.theme["color"]["checkmark"] if checkmark_color == "default_theme" else checkmark_color
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# shape
|
2022-10-02 04:23:10 +03:00
|
|
|
self._corner_radius = ThemeManager.theme["shape"]["checkbox_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
|
|
|
self._border_width = ThemeManager.theme["shape"]["checkbox_border_width"] if border_width == "default_theme" else border_width
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# text
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text = text
|
|
|
|
self._text_label: Union[tkinter.Label, None] = None
|
|
|
|
self._text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
|
|
|
self._text_color_disabled = ThemeManager.theme["color"]["text_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
2022-10-03 01:33:06 +03:00
|
|
|
self._font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if font == "default_theme" else font
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# callback and hover functionality
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = command
|
|
|
|
self._state = state
|
|
|
|
self._hover = hover
|
|
|
|
self._check_state = False
|
|
|
|
|
|
|
|
self._onvalue = onvalue
|
|
|
|
self._offvalue = offvalue
|
|
|
|
self._variable: tkinter.Variable = variable
|
|
|
|
self._variable_callback_blocked = False
|
|
|
|
self._textvariable: tkinter.Variable = textvariable
|
|
|
|
self._variable_callback_name = None
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# configure grid system (1x3)
|
2022-03-05 15:05:39 +03:00
|
|
|
self.grid_columnconfigure(0, weight=0)
|
2022-10-02 04:23:10 +03:00
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self._apply_widget_scaling(6))
|
2022-03-05 15:05:39 +03:00
|
|
|
self.grid_columnconfigure(2, weight=1)
|
2022-04-21 19:34:58 +03:00
|
|
|
self.grid_rowconfigure(0, weight=1)
|
2022-03-05 15:05:39 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._bg_canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
|
|
|
width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
|
|
|
|
|
|
|
|
self._canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
|
|
|
width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=1, rowspan=1)
|
|
|
|
self._draw_engine = DrawEngine(self._canvas)
|
|
|
|
|
|
|
|
self._canvas.bind("<Enter>", self._on_enter)
|
|
|
|
self._canvas.bind("<Leave>", self._on_leave)
|
|
|
|
self._canvas.bind("<Button-1>", self.toggle)
|
|
|
|
|
|
|
|
self._text_label = tkinter.Label(master=self,
|
|
|
|
bd=0,
|
|
|
|
text=self._text,
|
|
|
|
justify=tkinter.LEFT,
|
2022-10-03 01:33:06 +03:00
|
|
|
font=self._apply_font_scaling(self._font),
|
2022-10-02 04:23:10 +03:00
|
|
|
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-02 01:54:21 +03:00
|
|
|
|
2022-07-05 15:39:12 +03:00
|
|
|
# register variable callback and set state according to variable
|
2022-10-02 04:23:10 +03:00
|
|
|
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
|
2022-07-05 15:39:12 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._draw() # initial draw
|
|
|
|
self._set_cursor()
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_scaling(self, *args, **kwargs):
|
|
|
|
super()._set_scaling(*args, **kwargs)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self._apply_widget_scaling(6))
|
2022-10-03 01:33:06 +03:00
|
|
|
self._text_label.configure(font=self._apply_font_scaling(self._font))
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.delete("checkmark")
|
|
|
|
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))
|
|
|
|
self._draw()
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
def destroy(self):
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None:
|
|
|
|
self._variable.trace_remove("write", self._variable_callback_name)
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-01-02 00:16:06 +03:00
|
|
|
super().destroy()
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _draw(self, no_color_updates=False):
|
|
|
|
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._current_width),
|
|
|
|
self._apply_widget_scaling(self._current_height),
|
|
|
|
self._apply_widget_scaling(self._corner_radius),
|
|
|
|
self._apply_widget_scaling(self._border_width))
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._check_state is True:
|
|
|
|
self._draw_engine.draw_checkmark(self._apply_widget_scaling(self._current_width),
|
|
|
|
self._apply_widget_scaling(self._current_height),
|
|
|
|
self._apply_widget_scaling(self._current_height * 0.58))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.delete("checkmark")
|
2022-03-09 16:49:44 +03:00
|
|
|
|
2022-10-02 04:23:10 +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-02-23 01:50:03 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._check_state is True:
|
|
|
|
self._canvas.itemconfig("inner_parts",
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
|
|
|
self._canvas.itemconfig("border_parts",
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
2022-02-23 01:50:03 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if "create_line" in self._canvas.gettags("checkmark"):
|
|
|
|
self._canvas.itemconfig("checkmark", fill=ThemeManager.single_color(self._checkmark_color, self._appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("checkmark", fill=ThemeManager.single_color(self._checkmark_color, self._appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts",
|
|
|
|
outline=ThemeManager.single_color(self._bg_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
|
|
|
self._canvas.itemconfig("border_parts",
|
|
|
|
outline=ThemeManager.single_color(self._border_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._border_color, self._appearance_mode))
|
|
|
|
|
|
|
|
if self._state == tkinter.DISABLED:
|
|
|
|
self._text_label.configure(fg=(ThemeManager.single_color(self._text_color_disabled, self._appearance_mode)))
|
2022-03-10 04:12:30 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label.configure(fg=ThemeManager.single_color(self._text_color, self._appearance_mode))
|
2022-07-05 15:39:12 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
2021-11-11 00:17:49 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
def configure(self, require_redraw=False, **kwargs):
|
2021-08-25 18:02:16 +03:00
|
|
|
if "text" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text = kwargs.pop("text")
|
|
|
|
self._text_label.configure(text=self._text)
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
if "font" in kwargs:
|
|
|
|
self._font = kwargs.pop("font")
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._text_label is not None:
|
2022-10-03 01:33:06 +03:00
|
|
|
self._text_label.configure(font=self._apply_font_scaling(self._font))
|
2022-08-16 15:05:15 +03:00
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
if "state" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._state = kwargs.pop("state")
|
|
|
|
self._set_cursor()
|
2022-03-10 04:12:30 +03:00
|
|
|
require_redraw = True
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2021-11-07 00:06:27 +03:00
|
|
|
if "fg_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._fg_color = kwargs.pop("fg_color")
|
2021-11-07 00:06:27 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "hover_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._hover_color = kwargs.pop("hover_color")
|
2021-11-07 00:06:27 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "text_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_color = kwargs.pop("text_color")
|
2021-11-07 00:06:27 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "border_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._border_color = kwargs.pop("border_color")
|
2021-11-07 00:06:27 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-01-08 15:13:10 +03:00
|
|
|
if "command" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = kwargs.pop("command")
|
2022-01-08 15:13:10 +03:00
|
|
|
|
2022-07-02 01:54:21 +03:00
|
|
|
if "textvariable" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._textvariable = kwargs.pop("textvariable")
|
|
|
|
self._text_label.configure(textvariable=self._textvariable)
|
2022-07-02 01:54:21 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if "variable" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None and self._variable != "":
|
|
|
|
self._variable.trace_remove("write", self._variable_callback_name) # remove old variable callback
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._variable = kwargs.pop("variable")
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
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
|
2022-07-05 15:39:12 +03:00
|
|
|
require_redraw = True
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
super().configure(require_redraw=require_redraw, **kwargs)
|
2021-11-07 00:06:27 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
def cget(self, attribute_name: str) -> any:
|
|
|
|
if attribute_name == "corner_radius":
|
|
|
|
return self._corner_radius
|
|
|
|
elif attribute_name == "border_width":
|
|
|
|
return self._border_width
|
|
|
|
|
|
|
|
elif attribute_name == "fg_color":
|
|
|
|
return self._fg_color
|
|
|
|
elif attribute_name == "hover_color":
|
|
|
|
return self._hover_color
|
|
|
|
elif attribute_name == "border_color":
|
|
|
|
return self._border_color
|
|
|
|
elif attribute_name == "checkmark_color":
|
|
|
|
return self._checkmark_color
|
|
|
|
elif attribute_name == "text_color":
|
|
|
|
return self._text_color
|
|
|
|
elif attribute_name == "text_color_disabled":
|
|
|
|
return self._text_color_disabled
|
|
|
|
|
|
|
|
elif attribute_name == "text":
|
|
|
|
return self._text
|
|
|
|
elif attribute_name == "font":
|
|
|
|
return self._font
|
|
|
|
elif attribute_name == "textvariable":
|
|
|
|
return self._textvariable
|
|
|
|
elif attribute_name == "state":
|
|
|
|
return self._state
|
|
|
|
elif attribute_name == "hover":
|
|
|
|
return self._hover
|
|
|
|
elif attribute_name == "onvalue":
|
|
|
|
return self._onvalue
|
|
|
|
elif attribute_name == "offvalue":
|
|
|
|
return self._offvalue
|
|
|
|
elif attribute_name == "variable":
|
|
|
|
return self._variable
|
|
|
|
else:
|
|
|
|
return super().cget(attribute_name)
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_cursor(self):
|
2022-05-17 22:44:59 +03:00
|
|
|
if Settings.cursor_manipulation_enabled:
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._state == tkinter.DISABLED:
|
2022-05-17 22:44:59 +03:00
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(cursor="arrow")
|
|
|
|
if self._text_label is not None:
|
|
|
|
self._text_label.configure(cursor="arrow")
|
2022-05-17 22:44:59 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(cursor="arrow")
|
|
|
|
if self._text_label is not None:
|
|
|
|
self._text_label.configure(cursor="arrow")
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._state == tkinter.NORMAL:
|
2022-05-17 22:44:59 +03:00
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(cursor="pointinghand")
|
|
|
|
if self._text_label is not None:
|
|
|
|
self._text_label.configure(cursor="pointinghand")
|
2022-05-17 22:44:59 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(cursor="hand2")
|
|
|
|
if self._text_label is not None:
|
|
|
|
self._text_label.configure(cursor="hand2")
|
|
|
|
|
|
|
|
def _on_enter(self, event=0):
|
|
|
|
if self._hover is True and self._state == tkinter.NORMAL:
|
|
|
|
if self._check_state is True:
|
|
|
|
self._canvas.itemconfig("inner_parts",
|
|
|
|
fill=ThemeManager.single_color(self._hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._hover_color, self._appearance_mode))
|
|
|
|
self._canvas.itemconfig("border_parts",
|
|
|
|
fill=ThemeManager.single_color(self._hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._hover_color, self._appearance_mode))
|
2022-03-10 04:12:30 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts",
|
|
|
|
fill=ThemeManager.single_color(self._hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._hover_color, self._appearance_mode))
|
|
|
|
|
|
|
|
def _on_leave(self, event=0):
|
|
|
|
if self._hover is True:
|
|
|
|
if self._check_state is True:
|
|
|
|
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))
|
|
|
|
self._canvas.itemconfig("border_parts",
|
|
|
|
fill=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
2021-08-25 18:02:16 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts",
|
|
|
|
fill=ThemeManager.single_color(self._bg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
|
|
|
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))
|
|
|
|
|
|
|
|
def _variable_callback(self, var_name, index, mode):
|
|
|
|
if not self._variable_callback_blocked:
|
|
|
|
if self._variable.get() == self._onvalue:
|
2022-01-16 18:54:21 +03:00
|
|
|
self.select(from_variable_callback=True)
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._variable.get() == self._offvalue:
|
2022-01-16 18:54:21 +03:00
|
|
|
self.deselect(from_variable_callback=True)
|
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
def toggle(self, event=0):
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._state == tkinter.NORMAL:
|
|
|
|
if self._check_state is True:
|
|
|
|
self._check_state = False
|
|
|
|
self._draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._check_state = True
|
|
|
|
self._draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-02 04:23:10 +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-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._command is not None:
|
|
|
|
self._command()
|
2022-06-05 13:32:11 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
def select(self, from_variable_callback=False):
|
2022-10-02 04:23:10 +03:00
|
|
|
self._check_state = True
|
|
|
|
self._draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-02 04:23:10 +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-01-16 18:54:21 +03:00
|
|
|
|
|
|
|
def deselect(self, from_variable_callback=False):
|
2022-10-02 04:23:10 +03:00
|
|
|
self._check_state = False
|
|
|
|
self._draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-10-02 04:23:10 +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-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def get(self) -> Union[int, str]:
|
|
|
|
return self._onvalue if self._check_state is True else self._offvalue
|
2022-10-04 03:26:29 +03:00
|
|
|
|
|
|
|
def bind(self, sequence=None, command=None, add=None):
|
|
|
|
""" called on the tkinter.Canvas """
|
|
|
|
return self._canvas.bind(sequence, command, add)
|
2022-10-04 04:03:43 +03:00
|
|
|
|
|
|
|
def unbind(self, sequence, funcid=None):
|
|
|
|
""" called on the tkinter.Canvas """
|
2022-10-04 04:16:59 +03:00
|
|
|
return self._canvas.unbind(sequence, funcid)
|
2022-10-05 22:11:46 +03:00
|
|
|
|
|
|
|
def focus(self):
|
|
|
|
return self._text_label.focus()
|
|
|
|
|
|
|
|
def focus_set(self):
|
|
|
|
return self._text_label.focus_set()
|
|
|
|
|
|
|
|
def focus_force(self):
|
|
|
|
return self._text_label.focus_force()
|