py 安装程序 "could not parse stylesheet"
pyinstaller "could not parse stylesheet"
我正在使用 pyQt 和 pyInstaller 构建一个小程序。
我尝试将背景图像添加到我的 QMainWindow:
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 wiki 复制的,returns 绝对路径并且适用于其他 pictures/icons。
但是,如果我使用 pyInstaller 构建可执行文件,程序 运行 很好,但缺少背景图像。相反,控制台输出
"could not parse stylesheet of object ..."
如果我 运行 python 文件,一切正常...
对此有什么想法吗?
谢谢!
我会回答我自己的问题,以防其他人遇到同样的问题。
文件分隔符错误...
用
修复它
bgpath = os.path.join(self.py_prima.resource_path(), "bg.png")
bgpath = bgpath.replace("\", "/")
self.setStyleSheet("QMainWindow{{border-image: url({0});background-size: 100%;}}".format(
bgpath))
我正在使用 pyQt 和 pyInstaller 构建一个小程序。 我尝试将背景图像添加到我的 QMainWindow:
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 wiki 复制的,returns 绝对路径并且适用于其他 pictures/icons。 但是,如果我使用 pyInstaller 构建可执行文件,程序 运行 很好,但缺少背景图像。相反,控制台输出
"could not parse stylesheet of object ..."
如果我 运行 python 文件,一切正常...
对此有什么想法吗?
谢谢!
我会回答我自己的问题,以防其他人遇到同样的问题。
文件分隔符错误... 用
修复它bgpath = os.path.join(self.py_prima.resource_path(), "bg.png")
bgpath = bgpath.replace("\", "/")
self.setStyleSheet("QMainWindow{{border-image: url({0});background-size: 100%;}}".format(
bgpath))