Skip to content

Commit 600d92d

Browse files
Add asset path utility for bundled assets and update banner image loading
1 parent 03b7719 commit 600d92d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

ui/main_window.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
- Added a "Batches" title above the table area at the bottom of the page.
1818
"""
1919

20+
import sys, os
2021
import tkinter as tk
22+
from pathlib import Path
2123
from tkinter import ttk
2224
import webbrowser
2325

@@ -74,6 +76,11 @@ def _open_help_docs():
7476
def _open_report_bug():
7577
webbrowser.open("https://github.com/tmaier-kettering/CodebookAI/issues/new")
7678

79+
def asset_path(*parts) -> str:
80+
# When frozen by PyInstaller, data are unpacked under sys._MEIPASS
81+
base = Path(getattr(sys, "_MEIPASS", Path(__file__).resolve().parent))
82+
return str(base.joinpath("assets", *parts))
83+
7784

7885
def build_ui(root: tk.Tk) -> None:
7986
"""
@@ -104,9 +111,9 @@ def build_ui(root: tk.Tk) -> None:
104111

105112
# Load and keep a reference to avoid garbage collection
106113
# (PNG with transparency is fine with tk.PhotoImage)
107-
orig = tk.PhotoImage(file="assets/Banner_Narrow_trans.png")
108-
scale_factor = 3 # make bigger number to shrink more
109-
root.banner_img = orig.subsample(scale_factor, scale_factor)
114+
banner_img = tk.PhotoImage(file=asset_path("Banner_Narrow_trans.png"))
115+
scale_factor = 3
116+
root.banner_img = banner_img.subsample(scale_factor, scale_factor) # keep a ref on root
110117

111118
banner_lbl = ttk.Label(header, image=root.banner_img, anchor="center")
112119
banner_lbl.grid(row=0, column=0, sticky="n", padx=0, pady=0)

0 commit comments

Comments
 (0)