0
我有两个python文件“main.py”和“mainLauncher.py”在同一个文件夹中。 所以如果我运行mainLauncher.py那么它成功运行并打开一个窗口,如下图所示,我提出申请。Python3程序进入非响应状态
为mainLauncher.py代码:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainLauncher(object):
def main_launcher_ui(self, WizardPage):
WizardPage.setObjectName("WizardPage")
WizardPage.resize(626, 284)
WizardPage.setStyleSheet("background-color:#e0e0e0;\n"
"border:none;")
self.textBrowser = QtWidgets.QTextBrowser(WizardPage)
self.textBrowser.setGeometry(QtCore.QRect(10, 20, 601, 51))
self.textBrowser.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.textBrowser.setStyleSheet("border:none;\n"
"color:#424242 ;\n"
"font-family:futura light;\n"
"")
self.textBrowser.setFrameShape(QtWidgets.QFrame.WinPanel)
self.textBrowser.setObjectName("textBrowser")
self.next = QtWidgets.QPushButton(WizardPage)
self.next.setGeometry(QtCore.QRect(390, 240, 84, 28))
self.next.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.next.setStyleSheet("border:1px solid #ccc;\n"
"background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ccc, stop: 1 #fff);")
self.next.setObjectName("next")
self.quit = QtWidgets.QPushButton(WizardPage)
self.quit.setGeometry(QtCore.QRect(490, 240, 84, 28))
self.quit.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.quit.setStyleSheet("border:1px solid #ccc;\n"
"background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ccc, stop: 1 #fff);")
self.quit.setObjectName("quit")
self.retranslateUi(WizardPage
QtCore.QMetaObject.connectSlotsByName(WizardPage)
def retranslateUi(self, WizardPage):
_translate = QtCore.QCoreApplication.translate
WizardPage.setWindowTitle(_translate("WizardPage", "WizardPage"))
self.textBrowser.setHtml(_translate("WizardPage",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'futura 53\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Cantarell\'; font-size:24pt; font-weight:600;\">Welcome to GDrive</span></p></body></html>"))
self.next.setText(_translate("WizardPage", "Next"))
self.quit.setText(_translate("WizardPage", "Quit"))
def retranslateUi(self, WizardPage):
_translate = QtCore.QCoreApplication.translate
WizardPage.setWindowTitle(_translate("WizardPage", "WizardPage"))
self.textBrowser.setHtml(_translate("WizardPage",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'futura 53\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Cantarell\'; font-size:24pt; font-weight:600;\">Welcome to GDrive</span></p></body></html>"))
self.next.setText(_translate("WizardPage", "Next"))
self.quit.setText(_translate("WizardPage", "Quit"))
def main_launch():
import sys
app = QtWidgets.QApplication(sys.argv)
WizardPage = QtWidgets.QWizardPage()
ui = Ui_MainLauncher()
ui.main_launcher_ui(WizardPage)
WizardPage.show()
sys.exit(app.exec_())
main_launch()
现在如果我删除从mainLauncher.py调用main_launch()功能和主要调用它。 py。所以我做了main.py为:
import sys
from PyQt5 import QtWidgets
from mainLauncher import main_launch
app = QtWidgets.QApplication(sys.argv)
main_launch() # calling of main_launch() which is in mainLaunch.py
sys.exit(app.exec_())
但如果我正在运行main.py则该窗口会在未响应状态,我要杀死从任务管理器过程而我得到以下输出:
谁能告诉我,为什么会发生,如何解决呢?我想从main.py运行main_launch()。
我已经测试你的代码,并删除了重复UI功能,我认为你复制它的形式没有意识到它,它可以正常工作,你可以共享通过驱动器,保管箱或类似的生成错误的完整代码。 – eyllanesc
@eyllanesc确定这是谷歌驱动器链接:https://drive.google.com/drive/folders/0B6dxEingt2ARUzFJbWhBQjdINk0?usp=sharing –
你需要Python3和PyQt5模块运行这段代码。 –