我想创建一个GUI EXE文件 我正在使用python 3.6和PyQt5创建一个GUI。在运行.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_())
答案 0 :(得分:1)
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_())