diff --git a/customtkinter/windows/widgets/font/font_manager.py b/customtkinter/windows/widgets/font/font_manager.py index 48c483b..df4d5e5 100644 --- a/customtkinter/windows/widgets/font/font_manager.py +++ b/customtkinter/windows/widgets/font/font_manager.py @@ -8,6 +8,7 @@ class FontManager: linux_font_path: str = "~/.fonts/" + darwin_font_path: str = "~/Library/Fonts/" @classmethod def init_font_manager(cls) -> bool: @@ -25,6 +26,15 @@ def init_font_manager(cls) -> bool: else: return True + @classmethod + def copy_fonts(cls, font_path: str, system_font_path: str) -> bool: + try: + shutil.copy(font_path, system_font_path) + return True + except Exception as err: + sys.stderr.write("FontManager error: " + str(err) + "\n") + return False + @classmethod def windows_load_font(cls, font_path: str | bytes, private: bool = True, enumerable: bool = False) -> bool: """ Function taken from: https://stackoverflow.com/questions/11993290/truly-custom-font-in-tkinter/30631309#30631309 """ @@ -55,13 +65,13 @@ def load_font(cls, font_path: str) -> bool: # Linux elif sys.platform.startswith("linux"): - try: - shutil.copy(font_path, os.path.expanduser(cls.linux_font_path)) - return True - except Exception as err: - sys.stderr.write("FontManager error: " + str(err) + "\n") - return False + return cls.copy_fonts(font_path, os.path.expanduser(cls.linux_font_path)) + + # macOS + elif sys.platform.startswith("darwin"): + return cls.copy_fonts(font_path, os.path.expanduser(cls.darwin_font_path)) + - # macOS and others + # others else: return False