PyQt5打包成exe

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cj675816156/article/details/79955028

mainwindow.py例如:

import os
import sys
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication, QMainWindow


class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        if getattr(sys, 'frozen', False):
            # we are running in a bundle
            bundle_dir = sys._MEIPASS
        else:
            # we are running in a normal Python environment
            bundle_dir = os.path.dirname(os.path.abspath(__file__))
        loadUi(os.path.join(bundle_dir, 'mainwindow.ui'), self)
        self.btn_select.pressed.connect(self.__btn_select_pressed)

    def __btn_select_pressed(self):
        print('Hello')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec())

打包成exe执行如下命令:

pyinstaller -F --add-data="mainwindow.ui;." .\mainwindow.py
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页