运行 将 py 转换为 exe 文件显示控制台而不是设计的 GUI

Running the converted py to exe file shows a console and not the designed GUI

我想创建一个 GUI EXE 文件 我正在使用 python 3.6 和 PyQt5 创建一个 GUI,在 运行ning .py 文件之后,我得到了我正在处理的设计。 但是,当我使用 Cx_Freeze 或 pyinstaller 将 .py 文件转换为 exe 文件时,然后我 运行 EXE 文件,GUI 不显示,而是显示控制台。

import sys 
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUi

completed = 0
accumulate = 0
class Main(QMainWindow):
    def __init__(self):
        super(Main, self).__init__()
        loadUi('progress.ui',self)
        self.setWindowTitle('Greeting')
        self.progressBar.setValue(0)
        self.increase.clicked.connect(self.increase_by10)
        self.reset.clicked.connect(self.resetprogress)

    @pyqtSlot()
    def increase_by10(self):
        global accumulate
        accumulate += 10
        if accumulate <= 100:
                self.progressBar.setValue(accumulate)

    @pyqtSlot()
    def resetprogress(self):
        global accumulate
        accumulate = 0
        self.progressBar.setValue(accumulate)
        
      
              
app = QApplication(sys.argv)
widget = Main()
widget.show()
sys.exit(app.exec_())

  1. ...\Python\Scripts\pyuic5.exe progress.ui -o progress.py -x
  2. + (progress.py) # - (progress.ui)

  3. pyinstaller --onefile --noconsole main.py
  4. main.exe

main.py

import sys 
from PyQt5.QtCore import pyqtSlot, QThread       #++++++++ QThread
from PyQt5.QtWidgets import QApplication, QMainWindow
#from PyQt5.uic import loadUi                     #--------

import progress                                  #++++++++

completed = 0
accumulate = 0
class Main(QMainWindow, progress.Ui_MainWindow): #++++++++ progress.Ui_MainWindow
    def __init__(self):
        super(Main, self).__init__()

        self.setupUi(self)                       #+++++++++
        #loadUi('progress.ui',self)              #---------

        self.setWindowTitle('Greeting')
        self.progressBar.setValue(0)
        self.increase.clicked.connect(self.increase_by10)
        self.reset.clicked.connect(self.resetprogress)

    @pyqtSlot()
    def increase_by10(self):
        global accumulate
        #accumulate += 10                              #-----
        while accumulate <= 100:                       #+++++ 
            self.progressBar.setValue(accumulate)
            QThread.msleep(1000)                       #+++++
            accumulate += 10                           #+++++


    @pyqtSlot()
    def resetprogress(self):
        global accumulate
        accumulate = 0
        self.progressBar.setValue(accumulate)

app = QApplication(sys.argv)
widget = Main()
widget.show()
sys.exit(app.exec_())