Răsfoiți Sursa

Support frozen resource loading for PyInstaller Windows app export

Your Name 1 lună în urmă
părinte
comite
a79e503ab7
1 a modificat fișierele cu 9 adăugiri și 2 ștergeri
  1. 9 2
      main.py

+ 9 - 2
main.py

@@ -1,16 +1,23 @@
 import sys
+import os
 from PyQt6.QtWidgets import QApplication
 from ui.main_window import MainWindow
 
+def get_resource_path(relative_path):
+    if hasattr(sys, '_MEIPASS'):
+        return os.path.join(sys._MEIPASS, relative_path)
+    return os.path.join(os.path.abspath("."), relative_path)
+
 def main():
     app = QApplication(sys.argv)
     
     # Load stylesheet
+    style_path = get_resource_path(os.path.join("resources", "style.qss"))
     try:
-        with open("resources/style.qss", "r") as f:
+        with open(style_path, "r") as f:
             app.setStyleSheet(f.read())
     except FileNotFoundError:
-        print("Warning: style.qss not found, using default styling.")
+        print(f"Warning: style.qss not found at {style_path}, using default styling.")
 
     window = MainWindow()
     window.show()