1.代码增加
# 生成资源文件目录拜访门路def resource_path(self, resource_path): if getattr(sys, 'frozen', False): # 是否Bundle Resource base_path = sys._MEIPASS else: base_path = os.path.abspath(".") return os.path.join(base_path, resource_path)
2.调用办法
icon_path = self.resource_path(os.path.join("resource/orange.png"))self.icon = QIcon(icon_path)self.setWindowTitle('单据生成工具')self.setWindowIcon(self.icon)
3.执行命令生成.spec文件
pyinstaller -w -F main.py
4.批改.spec文件