从代码来看,错误是由第 102 行引起的。在那里,在加载模块时,您创建了一个QWidget(更准确地说是 a QMainWindow)。这发生在创建之前QApplication。
另外,我不知道为什么你有这个 start 变量,因为它似乎没有被使用。
如果要使用对象创建它,请在方法HelloBegin中移动它。__init__
编辑:
如果您想在加载模块时显示启动屏幕,您需要由一个小型、轻量级的模块启动应用程序。在本模块中,您将:
- 创建 QApplication
- 打开您的启动画面/消息框
- 然后才加载其他模块
为了一切顺利,我会在一个单独的函数中导入模块,并使用一个小技巧来确保它仅在 GUI 准备好后启动。代码将如下所示:
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QTimer
def startApp():
import m1
import m2
wnd = createWindow()
wnd.show()
import sys
app = QApplication(sys.argv)
splash = createSplashScreen()
splash.show()
QTimer.singleShot(1, startApp) # call startApp only after the GUI is ready
sys.exit(app.exec_())
createSplashScreen创建启动画面的函数在哪里