allow multiple style strings in font tuple #759

This commit is contained in:
Tom Schimansky 2022-12-06 18:29:09 +01:00
parent 6a3fa7fa29
commit 868b2a2f42
3 changed files with 4 additions and 5 deletions

View File

@ -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") 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"] 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 return font
else: else:
raise ValueError(f"Wrong font type {type(font)}\n" + 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"\nUsage example:\n" +
f"font=customtkinter.CTkFont(family='<name>', size=<size in px>)\n" + f"font=customtkinter.CTkFont(family='<name>', size=<size in px>)\n" +
f"font=('<name>', <size in px>)\n") f"font=('<name>', <size in px>)\n")

View File

@ -55,7 +55,6 @@ class CTkFont(Font):
self._size_configure_callback_list.remove(callback) self._size_configure_callback_list.remove(callback)
def create_scaled_tuple(self, font_scaling: float) -> Tuple[str, int, str]: 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 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 return self._family, round(-abs(self._size) * font_scaling), self._tuple_style_string

View File

@ -82,8 +82,8 @@ class CTkScalingBaseClass:
return font return font
elif len(font) == 2: elif len(font) == 2:
return font[0], -abs(round(font[1] * self.__widget_scaling)) return font[0], -abs(round(font[1] * self.__widget_scaling))
elif len(font) == 3: elif 3 <= len(font) <= 6:
return font[0], -abs(round(font[1] * self.__widget_scaling)), font[2] return font[0], -abs(round(font[1] * self.__widget_scaling)), font[2:]
else: else:
raise ValueError(f"Can not scale font {font}. font needs to be tuple of len 1, 2 or 3") raise ValueError(f"Can not scale font {font}. font needs to be tuple of len 1, 2 or 3")