From 868b2a2f42c4b1e78c9e6d7ddfb7c64481cd4c24 Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Tue, 6 Dec 2022 18:29:09 +0100 Subject: [PATCH] allow multiple style strings in font tuple #759 --- .../windows/widgets/core_widget_classes/ctk_base_class.py | 4 ++-- customtkinter/windows/widgets/font/ctk_font.py | 1 - customtkinter/windows/widgets/scaling/scaling_base_class.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py index 500b997..8b389f3 100644 --- a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py +++ b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py @@ -161,12 +161,12 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas sys.stderr.write(f"{type(self).__name__} Warning: font {font} given without size, will be extended with default text size of current theme\n") return font[0], ThemeManager.theme["text"]["size"] - elif type(font) == tuple and 2 <= len(font) <= 3: + elif type(font) == tuple and 2 <= len(font) <= 6: return font else: raise ValueError(f"Wrong font type {type(font)}\n" + - f"For consistency, Customtkinter requires the font argument to be a tuple of len 2 or 3 or an instance of CTkFont.\n" + + f"For consistency, Customtkinter requires the font argument to be a tuple of len 2 to 6 or an instance of CTkFont.\n" + f"\nUsage example:\n" + f"font=customtkinter.CTkFont(family='', size=)\n" + f"font=('', )\n") diff --git a/customtkinter/windows/widgets/font/ctk_font.py b/customtkinter/windows/widgets/font/ctk_font.py index bdfae07..551b3a6 100644 --- a/customtkinter/windows/widgets/font/ctk_font.py +++ b/customtkinter/windows/widgets/font/ctk_font.py @@ -55,7 +55,6 @@ class CTkFont(Font): self._size_configure_callback_list.remove(callback) def create_scaled_tuple(self, font_scaling: float) -> Tuple[str, int, str]: - """ return scaled tuple representation of font in the form (family: str, size: int, style: str)""" return self._family, round(-abs(self._size) * font_scaling), self._tuple_style_string diff --git a/customtkinter/windows/widgets/scaling/scaling_base_class.py b/customtkinter/windows/widgets/scaling/scaling_base_class.py index 74838bc..0d7b29b 100644 --- a/customtkinter/windows/widgets/scaling/scaling_base_class.py +++ b/customtkinter/windows/widgets/scaling/scaling_base_class.py @@ -82,8 +82,8 @@ class CTkScalingBaseClass: return font elif len(font) == 2: return font[0], -abs(round(font[1] * self.__widget_scaling)) - elif len(font) == 3: - return font[0], -abs(round(font[1] * self.__widget_scaling)), font[2] + elif 3 <= len(font) <= 6: + return font[0], -abs(round(font[1] * self.__widget_scaling)), font[2:] else: raise ValueError(f"Can not scale font {font}. font needs to be tuple of len 1, 2 or 3")