已解决-答案已发布,谢谢所有人的帮助。
使用PyQt5
将python应用程序编译为可执行文件后,GUI中包含的图标将被删除/不显示。
特别是使用self.setWindowIcon(QtGui.QIcon(fpath))
和通过label.setPixmap(myPixmap)
嵌入QLabel
中的QIcon
实例添加到我的Window(QMainWindow)
类中。在
我试着在这个论坛上搜索可能的解决方案,但找不到解决问题的线索。 我已经尝试将绝对文件路径设置为此处Bundling data files with PyInstaller (--onefile)和此处Missing button icons in pyinstaller
不知道从何处开始检查问题,使用pyinstaller
编译时没有错误,而且它作为python脚本运行良好。在
pyinstaller -w -F MY_GUI.py
提前谢谢!在
示例:
^{pr2}$import sys
import resource_path # code taken from links above
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.title = "MyProg"
self.top = 400
self.left = 400
self.width = 680
self.height = 540
icon_path = resource_path("icon.png")
self.setWindowIcon(QtGui.QIcon(icon_path))
self.InitUI()
def InitUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.top, self.left, self.width, self.height)
self.show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
解决方案是专门将图像文件添加到
.spec
文件中,然后使用以下是
^{pr2}$.spec
文件的相关部分:相关问题 更多 >
编程相关推荐