在 PyQt5 中创建启动画面 [英] Create Splash screen in PyQt5

查看:61
本文介绍了在 PyQt5 中创建启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 PyQt5 中使用 Python 创建一个启动画面.我搜索过,但我在 Pyqt4 中找到了,我对 PyQt4 一无所知,所以在这种情况下帮助我我会很感激

<小时>

示例 2

导入系统从 PyQt5 导入 QtCore、QtGui、QtWidgets # + QtWidgets导入系统从 PyQt5.QtWidgets 导入 QApplication、QLabel从 PyQt5.QtCore 导入 QTimer, Qt如果 __name__ == '__main__':app = QApplication(sys.argv)label = QLabel("""<字体颜色=红色大小=128><b>Hello PyQt,5秒后窗口消失!</b></font>""")# SplashScreen - 表示该窗口是启动画面.这是 .QSplashScreen 的默认类型# FramelessWindowHint - 创建一个无边框窗口.用户无法通过窗口系统移动或调整无边框窗口的大小.label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint)标签.show()# 5秒后自动退出QTimer.singleShot(5000, app.quit)sys.exit(app.exec_())

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

Splash screen in pyqt

解决方案

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_())

这篇关于在 PyQt5 中创建启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆