2022-05-25 23:14:38 +03:00
|
|
|
import tkinter
|
|
|
|
import sys
|
2022-10-02 04:23:10 +03:00
|
|
|
from typing import Union, Tuple, Callable
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
from .ctk_canvas import CTkCanvas
|
|
|
|
from ..theme_manager import ThemeManager
|
|
|
|
from ..draw_engine import DrawEngine
|
|
|
|
from .widget_base_class import CTkBaseClass
|
2022-10-02 04:23:10 +03:00
|
|
|
from .dropdown_menu import DropdownMenu
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CTkOptionMenu(CTkBaseClass):
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
2022-10-03 01:33:06 +03:00
|
|
|
Optionmenu with rounded corners, dropdown menu, variable support, command.
|
2022-10-02 04:23:10 +03:00
|
|
|
For detailed information check out the documentation.
|
|
|
|
"""
|
|
|
|
|
2022-10-06 16:53:52 +03:00
|
|
|
def __init__(self,
|
|
|
|
master: any = None,
|
2022-10-03 01:33:06 +03:00
|
|
|
width: int = 140,
|
|
|
|
height: int = 28,
|
|
|
|
corner_radius: 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",
|
|
|
|
button_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
button_hover_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
|
|
|
dropdown_fg_color: Union[str, Tuple[str, str]] = "default_theme",
|
2022-10-02 04:23:10 +03:00
|
|
|
dropdown_hover_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
dropdown_text_color: Union[str, Tuple[str, str]] = "default_theme",
|
2022-10-03 01:33:06 +03:00
|
|
|
|
|
|
|
font: any = "default_theme",
|
2022-10-22 15:24:04 +03:00
|
|
|
dropdown_font: any = "default_theme",
|
2022-10-03 01:33:06 +03:00
|
|
|
values: list = None,
|
|
|
|
variable: tkinter.Variable = None,
|
2022-10-02 04:23:10 +03:00
|
|
|
state: str = tkinter.NORMAL,
|
2022-10-03 01:33:06 +03:00
|
|
|
hover: bool = True,
|
2022-10-10 01:48:08 +03:00
|
|
|
command: Callable[[str], None] = None,
|
2022-10-02 04:23:10 +03:00
|
|
|
dynamic_resizing: bool = True,
|
2022-10-22 15:24:04 +03:00
|
|
|
anchor: str = "w",
|
2022-05-25 23:14:38 +03:00
|
|
|
**kwargs):
|
|
|
|
|
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-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
# color variables
|
2022-10-02 04:23:10 +03:00
|
|
|
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
|
|
|
self._button_color = ThemeManager.theme["color"]["optionmenu_button"] if button_color == "default_theme" else button_color
|
|
|
|
self._button_hover_color = ThemeManager.theme["color"]["optionmenu_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
# shape
|
2022-10-02 04:23:10 +03:00
|
|
|
self._corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
# text and font
|
2022-10-08 02:50:09 +03:00
|
|
|
self._text_color = ThemeManager.theme["color"]["text_button"] if text_color == "default_theme" else text_color
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_color_disabled = ThemeManager.theme["color"]["text_button_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
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
# callback and hover functionality
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = command
|
|
|
|
self._variable = variable
|
|
|
|
self._variable_callback_blocked: bool = False
|
|
|
|
self._variable_callback_name: Union[str, None] = None
|
|
|
|
self._state = state
|
|
|
|
self._hover = hover
|
|
|
|
self._dynamic_resizing = dynamic_resizing
|
2022-05-31 23:32:21 +03:00
|
|
|
|
2022-05-25 23:14:38 +03:00
|
|
|
if values is None:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._values = ["CTkOptionMenu"]
|
2022-05-25 23:14:38 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._values = values
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if len(self._values) > 0:
|
|
|
|
self._current_value = self._values[0]
|
2022-05-31 23:32:21 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._current_value = "CTkOptionMenu"
|
2022-05-31 23:32:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._dropdown_menu = DropdownMenu(master=self,
|
|
|
|
values=self._values,
|
|
|
|
command=self._dropdown_callback,
|
2022-10-03 01:33:06 +03:00
|
|
|
fg_color=dropdown_fg_color,
|
2022-10-02 04:23:10 +03:00
|
|
|
hover_color=dropdown_hover_color,
|
|
|
|
text_color=dropdown_text_color,
|
2022-10-22 15:24:04 +03:00
|
|
|
font=dropdown_font)
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
# configure grid system (1x1)
|
|
|
|
self.grid_rowconfigure(0, weight=1)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
|
|
|
width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._draw_engine = DrawEngine(self._canvas)
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label = tkinter.Label(master=self,
|
2022-10-03 01:33:06 +03:00
|
|
|
font=self._apply_font_scaling(self._font),
|
2022-10-22 15:24:04 +03:00
|
|
|
anchor=anchor,
|
2022-10-13 18:28:33 +03:00
|
|
|
padx=0,
|
|
|
|
pady=0,
|
|
|
|
borderwidth=1,
|
2022-10-02 04:23:10 +03:00
|
|
|
text=self._current_value)
|
2022-10-22 15:24:04 +03:00
|
|
|
self._create_grid()
|
2022-10-02 04:23:10 +03:00
|
|
|
|
|
|
|
if not self._dynamic_resizing:
|
2022-06-23 22:05:44 +03:00
|
|
|
self.grid_propagate(0)
|
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if self._cursor_manipulation_enabled:
|
2022-06-15 00:58:21 +03:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
self.configure(cursor="pointinghand")
|
|
|
|
elif sys.platform.startswith("win"):
|
|
|
|
self.configure(cursor="hand2")
|
|
|
|
|
2022-05-25 23:14:38 +03:00
|
|
|
# event bindings
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.bind("<Enter>", self._on_enter)
|
|
|
|
self._canvas.bind("<Leave>", self._on_leave)
|
|
|
|
self._canvas.bind("<Button-1>", self._clicked)
|
|
|
|
self._canvas.bind("<Button-1>", self._clicked)
|
2022-06-15 02:24:02 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label.bind("<Enter>", self._on_enter)
|
|
|
|
self._text_label.bind("<Leave>", self._on_leave)
|
|
|
|
self._text_label.bind("<Button-1>", self._clicked)
|
|
|
|
self._text_label.bind("<Button-1>", self._clicked)
|
2022-06-15 02:24:02 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._draw() # initial draw
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None:
|
|
|
|
self._variable_callback_name = self._variable.trace_add("write", self._variable_callback)
|
|
|
|
self._current_value = self._variable.get()
|
|
|
|
self._text_label.configure(text=self._current_value)
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
def _create_grid(self):
|
|
|
|
self._canvas.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="nsew")
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-06-28 12:16:28 +03:00
|
|
|
left_section_width = self._current_width - self._current_height
|
2022-10-22 15:24:04 +03:00
|
|
|
self._text_label.grid(row=0, column=0, sticky="ew",
|
2022-10-02 04:23:10 +03:00
|
|
|
padx=(max(self._apply_widget_scaling(self._corner_radius), self._apply_widget_scaling(3)),
|
|
|
|
max(self._apply_widget_scaling(self._current_width - left_section_width + 3), self._apply_widget_scaling(3))))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
def _set_scaling(self, *args, **kwargs):
|
|
|
|
super()._set_scaling(*args, **kwargs)
|
|
|
|
|
|
|
|
# change label font size and grid padding
|
|
|
|
self._text_label.configure(font=self._apply_font_scaling(self._font))
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
2022-10-22 15:24:04 +03:00
|
|
|
self._create_grid()
|
2022-10-15 02:02:54 +03:00
|
|
|
self._draw(no_color_updates=True)
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_dimensions(self, width: int = None, height: int = None):
|
|
|
|
super()._set_dimensions(width, height)
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._draw()
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-08 02:50:09 +03:00
|
|
|
def destroy(self):
|
|
|
|
if self._variable is not None: # remove old callback
|
|
|
|
self._variable.trace_remove("write", self._variable_callback_name)
|
|
|
|
|
|
|
|
super().destroy()
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _draw(self, no_color_updates=False):
|
2022-05-31 23:32:21 +03:00
|
|
|
left_section_width = self._current_width - self._current_height
|
2022-10-02 04:23:10 +03:00
|
|
|
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border_vertical_split(self._apply_widget_scaling(self._current_width),
|
|
|
|
self._apply_widget_scaling(self._current_height),
|
|
|
|
self._apply_widget_scaling(self._corner_radius),
|
|
|
|
0,
|
|
|
|
self._apply_widget_scaling(left_section_width))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
requires_recoloring_2 = self._draw_engine.draw_dropdown_arrow(self._apply_widget_scaling(self._current_width - (self._current_height / 2)),
|
|
|
|
self._apply_widget_scaling(self._current_height / 2),
|
|
|
|
self._apply_widget_scaling(self._current_height / 3))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-05-27 02:09:54 +03:00
|
|
|
if no_color_updates is False or requires_recoloring or requires_recoloring_2:
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts_left",
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
|
|
|
self._canvas.itemconfig("inner_parts_right",
|
|
|
|
outline=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label.configure(fg=ThemeManager.single_color(self._text_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._state == tkinter.DISABLED:
|
|
|
|
self._text_label.configure(fg=(ThemeManager.single_color(self._text_color_disabled, self._appearance_mode)))
|
|
|
|
self._canvas.itemconfig("dropdown_arrow",
|
|
|
|
fill=ThemeManager.single_color(self._text_color_disabled, self._appearance_mode))
|
2022-05-25 23:14:38 +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))
|
|
|
|
self._canvas.itemconfig("dropdown_arrow",
|
|
|
|
fill=ThemeManager.single_color(self._text_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._text_label.configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.update_idletasks()
|
2022-06-23 22:05:44 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
def configure(self, require_redraw=False, **kwargs):
|
2022-10-22 15:24:04 +03:00
|
|
|
if "corner_radius" in kwargs:
|
|
|
|
self._corner_radius = kwargs.pop("corner_radius")
|
|
|
|
self._create_grid()
|
2022-05-25 23:14:38 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "fg_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._fg_color = kwargs.pop("fg_color")
|
2022-05-25 23:14:38 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-05-26 20:16:01 +03:00
|
|
|
if "button_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._button_color = kwargs.pop("button_color")
|
2022-05-26 20:16:01 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "button_hover_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._button_hover_color = kwargs.pop("button_hover_color")
|
2022-05-25 23:14:38 +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")
|
2022-05-25 23:14:38 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if "dropdown_color" in kwargs:
|
|
|
|
self._dropdown_menu.configure(fg_color=kwargs.pop("dropdown_color"))
|
|
|
|
|
|
|
|
if "dropdown_hover_color" in kwargs:
|
|
|
|
self._dropdown_menu.configure(hover_color=kwargs.pop("dropdown_hover_color"))
|
|
|
|
|
|
|
|
if "dropdown_text_color" in kwargs:
|
|
|
|
self._dropdown_menu.configure(text_color=kwargs.pop("dropdown_text_color"))
|
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
if "font" in kwargs:
|
|
|
|
self._font = kwargs.pop("font")
|
|
|
|
self._text_label.configure(font=self._apply_font_scaling(self._font))
|
2022-08-16 15:05:15 +03:00
|
|
|
|
2022-05-25 23:14:38 +03:00
|
|
|
if "command" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = kwargs.pop("command")
|
2022-05-25 23:14:38 +03:00
|
|
|
|
|
|
|
if "variable" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None: # remove old callback
|
|
|
|
self._variable.trace_remove("write", self._variable_callback_name)
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._variable = kwargs.pop("variable")
|
2022-05-27 01:12:37 +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._current_value = self._variable.get()
|
|
|
|
self._text_label.configure(text=self._current_value)
|
2022-05-27 01:12:37 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._variable = None
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-05-31 23:32:21 +03:00
|
|
|
if "values" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._values = kwargs.pop("values")
|
|
|
|
self._dropdown_menu.configure(values=self._values)
|
2022-05-31 23:32:21 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if "dropdown_font" in kwargs:
|
|
|
|
self._dropdown_menu.configure(font=kwargs.pop("dropdown_font"))
|
2022-06-15 02:24:02 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if "hover" in kwargs:
|
|
|
|
self._hover = kwargs.pop("hover")
|
2022-06-15 02:24:02 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if "state" in kwargs:
|
|
|
|
self._state = kwargs.pop("state")
|
|
|
|
require_redraw = True
|
2022-06-23 22:05:44 +03:00
|
|
|
|
|
|
|
if "dynamic_resizing" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._dynamic_resizing = kwargs.pop("dynamic_resizing")
|
|
|
|
if not self._dynamic_resizing:
|
2022-06-23 22:05:44 +03:00
|
|
|
self.grid_propagate(0)
|
|
|
|
else:
|
|
|
|
self.grid_propagate(1)
|
2022-06-15 02:24:02 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if "anchor" in kwargs:
|
|
|
|
self._text_label.configure(anchor=kwargs.pop("anchor"))
|
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
super().configure(require_redraw=require_redraw, **kwargs)
|
2022-05-25 23:14:38 +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 == "fg_color":
|
|
|
|
return self._fg_color
|
|
|
|
elif attribute_name == "button_color":
|
|
|
|
return self._button_color
|
|
|
|
elif attribute_name == "button_hover_color":
|
|
|
|
return self._button_hover_color
|
|
|
|
elif attribute_name == "text_color":
|
|
|
|
return self._text_color
|
|
|
|
elif attribute_name == "text_color_disabled":
|
|
|
|
return self._text_color_disabled
|
|
|
|
elif attribute_name == "dropdown_fg_color":
|
|
|
|
return self._dropdown_menu.cget("fg_color")
|
|
|
|
elif attribute_name == "dropdown_hover_color":
|
|
|
|
return self._dropdown_menu.cget("hover_color")
|
|
|
|
elif attribute_name == "dropdown_text_color":
|
|
|
|
return self._dropdown_menu.cget("text_color")
|
|
|
|
|
|
|
|
elif attribute_name == "font":
|
|
|
|
return self._font
|
2022-10-22 15:24:04 +03:00
|
|
|
elif attribute_name == "dropdown_font":
|
|
|
|
return self._dropdown_menu.cget("font")
|
2022-10-03 01:33:06 +03:00
|
|
|
elif attribute_name == "values":
|
|
|
|
return self._values
|
|
|
|
elif attribute_name == "variable":
|
|
|
|
return self._variable
|
|
|
|
elif attribute_name == "state":
|
|
|
|
return self._state
|
|
|
|
elif attribute_name == "hover":
|
|
|
|
return self._hover
|
|
|
|
elif attribute_name == "command":
|
|
|
|
return self._command
|
|
|
|
elif attribute_name == "dynamic_resizing":
|
|
|
|
return self._dynamic_resizing
|
2022-10-22 15:24:04 +03:00
|
|
|
elif attribute_name == "anchor":
|
|
|
|
return self._text_label.cget("anchor")
|
2022-10-04 04:03:43 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
else:
|
|
|
|
return super().cget(attribute_name)
|
|
|
|
|
2022-10-02 04:59:54 +03:00
|
|
|
def _open_dropdown_menu(self):
|
|
|
|
self._dropdown_menu.open(self.winfo_rootx(),
|
|
|
|
self.winfo_rooty() + self._apply_widget_scaling(self._current_height + 0))
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _on_enter(self, event=0):
|
|
|
|
if self._hover is True and self._state == tkinter.NORMAL and len(self._values) > 0:
|
2022-05-25 23:14:38 +03:00
|
|
|
# set color of inner button parts to hover color
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts_right",
|
|
|
|
outline=ThemeManager.single_color(self._button_hover_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._button_hover_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _on_leave(self, event=0):
|
2022-10-22 15:24:04 +03:00
|
|
|
# set color of inner button parts
|
|
|
|
self._canvas.itemconfig("inner_parts_right",
|
|
|
|
outline=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
2022-05-25 23:14:38 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _variable_callback(self, var_name, index, mode):
|
|
|
|
if not self._variable_callback_blocked:
|
|
|
|
self._current_value = self._variable.get()
|
|
|
|
self._text_label.configure(text=self._current_value)
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _dropdown_callback(self, value: str):
|
|
|
|
self._current_value = value
|
|
|
|
self._text_label.configure(text=self._current_value)
|
2022-05-27 01:12:37 +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._current_value)
|
|
|
|
self._variable_callback_blocked = False
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._command is not None:
|
|
|
|
self._command(self._current_value)
|
2022-09-16 00:55:55 +03:00
|
|
|
|
|
|
|
def set(self, value: str):
|
2022-10-02 04:23:10 +03:00
|
|
|
self._current_value = value
|
|
|
|
self._text_label.configure(text=self._current_value)
|
2022-09-16 00:55:55 +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._current_value)
|
|
|
|
self._variable_callback_blocked = False
|
2022-05-30 17:46:36 +03:00
|
|
|
|
2022-05-27 01:12:37 +03:00
|
|
|
def get(self) -> str:
|
2022-10-02 04:23:10 +03:00
|
|
|
return self._current_value
|
2022-05-27 01:12:37 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _clicked(self, event=0):
|
|
|
|
if self._state is not tkinter.DISABLED and len(self._values) > 0:
|
|
|
|
self._open_dropdown_menu()
|
2022-10-04 03:26:29 +03:00
|
|
|
|
2022-10-04 17:55:34 +03:00
|
|
|
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: 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)
|
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()
|