I want to create a splash screen in PyQt5
using Python. I searched but I found in Pyqt4
and I have no understanding of PyQt4 so help me in this case I would be gratful
Advertisement
Answer
Try it:
import sys from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QApplication, QSplashScreen from PyQt5.QtCore import QTimer class Dialog(QDialog): def __init__(self, parent=None): super(Dialog, self).__init__(parent) self.b1 = QPushButton('Display screensaver') self.b1.clicked.connect(self.flashSplash) layout = QVBoxLayout() self.setLayout(layout) layout.addWidget(self.b1) def flashSplash(self): self.splash = QSplashScreen(QPixmap('D:/_Qt/img/pyqt.jpg')) # By default, SplashScreen will be in the center of the screen. # You can move it to a specific location if you want: # self.splash.move(10,10) self.splash.show() # Close SplashScreen after 2 seconds (2000 ms) QTimer.singleShot(2000, self.splash.close) if __name__ == '__main__': app = QApplication(sys.argv) main = Dialog() main.show() sys.exit(app.exec_())
Example 2
import sys from PyQt5 import QtCore, QtGui, QtWidgets # + QtWidgets import sys from PyQt5.QtWidgets import QApplication, QLabel from PyQt5.QtCore import QTimer, Qt if __name__ == '__main__': app = QApplication(sys.argv) label = QLabel(""" <font color=red size=128> <b>Hello PyQt, The window will disappear after 5 seconds!</b> </font>""") # SplashScreen - Indicates that the window is a splash screen. This is the default type for .QSplashScreen # FramelessWindowHint - Creates a borderless window. The user cannot move or resize the borderless window through the window system. label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint) label.show() # Automatically exit after 5 seconds QTimer.singleShot(5000, app.quit) sys.exit(app.exec_())