CustomTkinter
CustomTkinter copied to clipboard
Minor improvements and recommendations (merak related)
To be able to use Merak package building toolkit some minor code change would be required.
Could you please let us know if these changes proposed here below could be done/accepted? (I left the original code line there commented out)
- root
__init__.pyIs there any specific reason to importosandsyshere?__version__ = "5.2.2" #import os #import sys - Add PACKAGE_ROOT to
windows/widgets/utility/__init.py__from pathlib import Path PACKAGE_ROOT = Path(__file__).resolve().parents[3] # define package root for assets - Modify
windows/ctk_tk.pyThe utility import has different logic than other imports and addPACKAGE_ROOT:
Use#from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty from .widgets.utility import pop_from_dict_by_set, check_kwargs_empty, PACKAGE_ROOTPACKAGE_ROOT:#customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico")) self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico"))) - Modify
windows/ctk_toplevel.pyThe utility import has different logic than other imports and addPACKAGE_ROOT:
Use#from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty from .widgets.utility import pop_from_dict_by_set, check_kwargs_empty, PACKAGE_ROOTPACKAGE_ROOT:
and#customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))) self.after(200, lambda: self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico"))))#customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico")) self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico"))) - Modify
windows/widgets/fonts/__init.py__AddPACKAGE_ROOT:
Usefrom ..utility import PACKAGE_ROOTPACKAGE_ROOT:# load Roboto fonts (used on Windows/Linux) #customtkinter_directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) #FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf")) #FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf")) FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "Roboto", "Roboto-Regular.ttf"))) FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "Roboto", "Roboto-Medium.ttf"))) # load font necessary for rendering the widgets (used on Windows/Linux) #if FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False: if FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "CustomTkinter_shapes_font.otf"))) is False: - Modify
windows/widgets/themes/theme_manager.pyAddPACKAGE_ROOT:
Usefrom ..utility import PACKAGE_ROOTPACKAGE_ROOT:#customtkinter_path = pathlib.Path(script_directory).parent.parent.parent #with open(os.path.join(customtkinter_path, "assets", "themes", f"{theme_name_or_path}.json"), "r") as f: with open(str(PACKAGE_ROOT.joinpath("assets", "themes", f"{theme_name_or_path}.json")), "r") as f:
I can create a Pull request for these above, if that helps. I was able to test these on Windows but can't test on Linux or MacOS.
Thank you for your consideration!