From cd85a1c782b9c860ffa94240d9cda6bc3900293f Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Sat, 27 May 2023 12:48:46 +0200 Subject: [PATCH] added text_color_disabled to CTkLabel #1557, change license in setup.cfg --- customtkinter/windows/widgets/ctk_label.py | 17 +++++++++++++++++ examples/simple_example.py | 1 - setup.cfg | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/customtkinter/windows/widgets/ctk_label.py b/customtkinter/windows/widgets/ctk_label.py index 9679d74..0eb7831 100644 --- a/customtkinter/windows/widgets/ctk_label.py +++ b/customtkinter/windows/widgets/ctk_label.py @@ -31,6 +31,7 @@ class CTkLabel(CTkBaseClass): bg_color: Union[str, Tuple[str, str]] = "transparent", fg_color: Optional[Union[str, Tuple[str, str]]] = None, text_color: Optional[Union[str, Tuple[str, str]]] = None, + text_color_disabled: Optional[Union[str, Tuple[str, str]]] = None, text: str = "CTkLabel", font: Optional[Union[tuple, CTkFont]] = None, @@ -47,6 +48,14 @@ class CTkLabel(CTkBaseClass): self._fg_color = ThemeManager.theme["CTkLabel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color, transparency=True) self._text_color = ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else self._check_color_type(text_color) + if text_color_disabled is None: + if "text_color_disabled" in ThemeManager.theme["CTkLabel"]: + self._text_color_disabled = ThemeManager.theme["CTkLabel"]["text_color"] + else: + self._text_color_disabled = self._text_color + else: + self._text_color_disabled = self._check_color_type(text_color_disabled) + # shape self._corner_radius = ThemeManager.theme["CTkLabel"]["corner_radius"] if corner_radius is None else corner_radius @@ -161,6 +170,7 @@ class CTkLabel(CTkBaseClass): outline=self._apply_appearance_mode(self._bg_color)) self._label.configure(fg=self._apply_appearance_mode(self._text_color), + disabledforeground=self._apply_appearance_mode(self._text_color_disabled), bg=self._apply_appearance_mode(self._bg_color)) else: self._canvas.itemconfig("inner_parts", @@ -168,6 +178,7 @@ class CTkLabel(CTkBaseClass): outline=self._apply_appearance_mode(self._fg_color)) self._label.configure(fg=self._apply_appearance_mode(self._text_color), + disabledforeground=self._apply_appearance_mode(self._text_color_disabled), bg=self._apply_appearance_mode(self._fg_color)) self._canvas.configure(bg=self._apply_appearance_mode(self._bg_color)) @@ -186,6 +197,10 @@ class CTkLabel(CTkBaseClass): self._text_color = self._check_color_type(kwargs.pop("text_color")) require_redraw = True + if "text_color_disabled" in kwargs: + self._text_color_disabled = self._check_color_type(kwargs.pop("text_color_disabled")) + require_redraw = True + if "text" in kwargs: self._text = kwargs.pop("text") self._label.configure(text=self._text) @@ -230,6 +245,8 @@ class CTkLabel(CTkBaseClass): return self._fg_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 diff --git a/examples/simple_example.py b/examples/simple_example.py index faf4fcb..6999cc0 100644 --- a/examples/simple_example.py +++ b/examples/simple_example.py @@ -37,7 +37,6 @@ entry_1.pack(pady=10, padx=10) optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."]) optionmenu_1.pack(pady=10, padx=10) optionmenu_1.set("CTkOptionMenu") -optionmenu_1.configure(state="disabled", text_color_disabled="red") combobox_1 = customtkinter.CTkComboBox(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."]) combobox_1.pack(pady=10, padx=10) diff --git a/setup.cfg b/setup.cfg index 0582b6e..a57ae3b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ author = Tom Schimansky license = Creative Commons Zero v1.0 Universal license_file = LICENSE classifiers = - License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication + License :: MIT License Operating System :: OS Independent Programming Language :: Python :: 3 :: Only