Python PyQt5电影启动画面
Python PyQt5 movie splash screen
我想要一个 .mp4 或 .gif 文件作为启动画面。我正在使用 Python 3.8 和 PyQt5。我试着自己做,但没有成功。有人知道怎么做吗?
我试过这个:
import sys, time
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QSplashScreen, QApplication, QWidget
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 paintEvent(self, event):
painter = QPainter(self)
pixmap = self.movie.currentPixmap()
self.setMask(pixmap.mask())
painter.drawPixmap(0, 0, pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
movie = QMovie("splash.gif")
splash = MovieSplashScreen(movie)
splash.show()
start = time.time()
while movie.state() == QMovie.Running and time.time() < start + 10:
app.processEvents()
window = QWidget()
window.show()
splash.finish(window)
sys.exit(app.exec_())
您需要启动 QMovie
:
# ...
splash.show()
<b>splash.movie.start()</b>
# ...
我想要一个 .mp4 或 .gif 文件作为启动画面。我正在使用 Python 3.8 和 PyQt5。我试着自己做,但没有成功。有人知道怎么做吗?
我试过这个:
import sys, time
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QSplashScreen, QApplication, QWidget
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 paintEvent(self, event):
painter = QPainter(self)
pixmap = self.movie.currentPixmap()
self.setMask(pixmap.mask())
painter.drawPixmap(0, 0, pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
movie = QMovie("splash.gif")
splash = MovieSplashScreen(movie)
splash.show()
start = time.time()
while movie.state() == QMovie.Running and time.time() < start + 10:
app.processEvents()
window = QWidget()
window.show()
splash.finish(window)
sys.exit(app.exec_())
您需要启动 QMovie
:
# ...
splash.show()
<b>splash.movie.start()</b>
# ...