Pyinstaller+PyQt5生成带图片的exe

新建Test.py

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import  QWidget,QApplication
from PyQt5.QtGui import QIcon, QPixmap
import sys
import images


class Demo(QWidget):
    def __init__(self):
        super(Demo, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("测试->图片打包进exe")
        self.resize(500, 350)
        self.setWindowIcon(QIcon(':/Image/f10.ico'))
        self.gridLayout = QtWidgets.QGridLayout()

        self.label_1 = QtWidgets.QLabel('sss')
        self.label_1.setObjectName('label_1')
        self.label_1.setPixmap(QPixmap(":/Image/CS.png"))
        self.gridLayout.addWidget(self.label_1, 0,0,1,1)

        self.setLayout(self.gridLayout)


if __name__ == '__main__':
    myApp = QApplication(sys.argv)
    ui = Demo()
    ui.show()
    sys.exit(myApp.exec())

2.新建images.qrc

<RCC>
    <qresource prefix="/">
        <file>Image/CS.png</file>
        <file>Image/f10.ico</file>
        <file>Image/Yellow.gif</file>
    </qresource>
</RCC>

3.PyRcc5 -o images.py images.qrc

4.在Test.py中导入import images.py

图片路径为:/Image/f10.ico

5.pyinstaller -Fw -i ./Image/f10.ico PyQt5_Test.py 生成exe

我写了,但是没有生成exe,,不过应该没问题,因为我有另外一个文件就是照这种方法生成的,现在只是重新把思路整理了一下,顺便记录下来,如下图,可以看到项目中没有Image这个文件夹,一样可以显示图片。ok,对了,这个只适用于PyQt的文件,tkinker不能用

发布了17 篇原创文章 · 获赞 8 · 访问量 2654

猜你喜欢

转载自blog.csdn.net/qq_39295354/article/details/102835939