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:
JavaScript
x
34
34
1
import sys
2
from PyQt5.QtGui import QPixmap
3
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QApplication, QSplashScreen
4
from PyQt5.QtCore import QTimer
5
6
class Dialog(QDialog):
7
def __init__(self, parent=None):
8
super(Dialog, self).__init__(parent)
9
10
self.b1 = QPushButton('Display screensaver')
11
self.b1.clicked.connect(self.flashSplash)
12
13
layout = QVBoxLayout()
14
self.setLayout(layout)
15
layout.addWidget(self.b1)
16
17
def flashSplash(self):
18
self.splash = QSplashScreen(QPixmap('D:/_Qt/img/pyqt.jpg'))
19
20
# By default, SplashScreen will be in the center of the screen.
21
# You can move it to a specific location if you want:
22
# self.splash.move(10,10)
23
24
self.splash.show()
25
26
# Close SplashScreen after 2 seconds (2000 ms)
27
QTimer.singleShot(2000, self.splash.close)
28
29
if __name__ == '__main__':
30
app = QApplication(sys.argv)
31
main = Dialog()
32
main.show()
33
sys.exit(app.exec_())
34
Example 2
JavaScript
1
25
25
1
import sys
2
from PyQt5 import QtCore, QtGui, QtWidgets # + QtWidgets
3
4
5
import sys
6
from PyQt5.QtWidgets import QApplication, QLabel
7
from PyQt5.QtCore import QTimer, Qt
8
9
if __name__ == '__main__':
10
app = QApplication(sys.argv)
11
12
label = QLabel("""
13
<font color=red size=128>
14
<b>Hello PyQt, The window will disappear after 5 seconds!</b>
15
</font>""")
16
17
# SplashScreen - Indicates that the window is a splash screen. This is the default type for .QSplashScreen
18
# FramelessWindowHint - Creates a borderless window. The user cannot move or resize the borderless window through the window system.
19
label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint)
20
label.show()
21
22
# Automatically exit after 5 seconds
23
QTimer.singleShot(5000, app.quit)
24
sys.exit(app.exec_())
25