0

我正在尝试向我的 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 停止工作

我已经尝试了一切。如果我不添加启动画面,应用程序将完美关闭。但是,在我添加启动画面并关闭应用程序后,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()
4

0 回答 0