0
我使用pyQt和pyInstaller構建一個小程序。 我已嘗試將背景圖片添加到我的QMainWindow:pyinstaller「無法解析樣式表」
class pyPrimaMainWindow(QMainWindow):
def __init__(self):
...do some stuff...
self.setWindowIcon(QIcon(os.path.join(self.py_prima.resource_path(), "TH.ico"))) # <- this works
self.setStyleSheet("QMainWindow{{border-image: url({0});background-size:100%;}}".format(os.path.join(self.py_prima.resource_path(), "bg.png")))
的resource_path()方法看起來像這樣:
def resource_path(self):
""" Get absolute path to resource, works for dev and for PyInstaller """
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = getattr(sys, '_MEIPASS', "C:/Users/Tobias/eclipse/workspace/PyPrima/data/")
# except Exception:
# base_path =
print(base_path)
return base_path
它從pyinstaller維基複製,返回absoulte路徑和作品爲其他圖片/圖標。 但是,如果我用pyInstaller構建可執行文件,程序運行良好,但背景圖像丟失。相反,控制檯輸出
"could not parse stylesheet of object ..."
如果我跑python的文件,它工作一切正常...
在這個任何想法?
謝謝!