我正在尝试在我的PyQt4 GUI应用程序中添加启动画面。代码工作正常,直到我关闭应用程序,使Python崩溃“Python.exe已停止工作”。这是代码。
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
#Splashscreen
movie = QMovie("giphy-downsized.gif")
splash = MovieSplashScreen(movie)
splash.show()
start = time.time()
while movie.state() == QMovie.Running and time.time() < start + 10:
app.processEvents()
MainWindow = QtGui.QMainWindow()
splash.finish(MainWindow)
movie.stop()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
splash.close()
sys.exit(app.exec_())
我已经尝试了一切。如果我不添加闪屏,应用程序将完美关闭。但是,添加启动画面并关闭应用程序后,python崩溃了。因此,问题在于遗留在内存中的对象或类似的东西,但我还无法解决它。请帮忙。
class MovieSplashScreen(QSplashScreen):
def __init__(self, movie, parent = None):
movie.jumpToFrame(0)
pixmap = QPixmap(movie.frameRect().size())
QSplashScreen.__init__(self, pixmap)
self.movie = movie
self.movie.frameChanged.connect(self.repaint)
def showEvent(self, event):
self.movie.start()
def hideEvent(self, event):
self.movie.stop()
def paintEvent(self, event):
painter = QPainter(self)
pixmap = self.movie.currentPixmap()
self.setMask(pixmap.mask())
painter.drawPixmap(0, 0, pixmap)
def sizeHint(self):
return self.movie.scaledSize()