Skip to content

Commit

Permalink
use assets from within an executable on windows, removing errors with…
Browse files Browse the repository at this point in the history
… single file build with pyinstaller
  • Loading branch information
julrog committed Sep 3, 2023
1 parent aaa1ba1 commit 7cf9ac9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions customtkinter/windows/ctk_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def _windows_set_titlebar_icon(self):
# if not the user already called iconbitmap method, set icon
if not self._iconbitmap_method_called:
customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if hasattr(sys, '_MEIPASS'):
customtkinter_directory = sys._MEIPASS
self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))
except Exception:
pass
Expand Down
4 changes: 4 additions & 0 deletions customtkinter/windows/ctk_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self, *args,
# Set Windows titlebar icon
if sys.platform.startswith("win"):
customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if hasattr(sys, '_MEIPASS'):
customtkinter_directory = sys._MEIPASS
self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico")))
except Exception:
pass
Expand Down Expand Up @@ -208,6 +210,8 @@ def _windows_set_titlebar_icon(self):
# if not the user already called iconbitmap method, set icon
if not self._iconbitmap_method_called:
customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if hasattr(sys, '_MEIPASS'):
customtkinter_directory = sys._MEIPASS
self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))
except Exception:
pass
Expand Down
2 changes: 2 additions & 0 deletions customtkinter/windows/widgets/font/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

# 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__)))))
if hasattr(sys, '_MEIPASS'):
customtkinter_directory = sys._MEIPASS
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"))

Expand Down
6 changes: 4 additions & 2 deletions customtkinter/windows/widgets/theme/theme_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def load_theme(cls, theme_name_or_path: str):
script_directory = os.path.dirname(os.path.abspath(__file__))

if theme_name_or_path in cls._built_in_themes:
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:
customtkinter_directory = pathlib.Path(script_directory).parent.parent.parent
if hasattr(sys, '_MEIPASS'):
customtkinter_directory = sys._MEIPASS
with open(os.path.join(customtkinter_directory, "assets", "themes", f"{theme_name_or_path}.json"), "r") as f:
cls.theme = json.load(f)
else:
with open(theme_name_or_path, "r") as f:
Expand Down

0 comments on commit 7cf9ac9

Please sign in to comment.