pyside6 加载页面后自动进入主程序

思路

使用QTimer.singleShot(3000, self.openwindown).完成单发:3s后执行openwindown

代码

from PySide6.QtCore import Signal, QTimer
from PySide6.QtGui import QFont, Qt
from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout


class MainWindown(QWidget):
    def __init__(self):
        super().__init__()
        self.mainLayout = QVBoxLayout()
        self.label = QLabel('正在加载中。。。')
        self.label.setFont(QFont('微软雅黑', 50))
        self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)

        self.mainLayout.addWidget(self.label)
        self.setLayout(self.mainLayout)
        QTimer.singleShot(3000, self.openwindown)  # 等待3s后执行openwindown

    def openwindown(self):
        self.close()  # 关闭自己
        self.subwindown = SubWindow()
        self.subwindown.show()  # 打开子窗口


class SubWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('进入程序')
        self.label = QLabel('欢迎进入主程序')
        self.label.setFont(QFont('微软雅黑', 30))
        self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.mainLayout = QVBoxLayout()
        self.mainLayout.addWidget(self.label)
        self.setLayout(self.mainLayout)



if __name__ == '__main__':
    app = QApplication([])
    window = MainWindown()
    window.show()
    app.exec()
posted @ 2024-01-03 14:44  Tarzen  阅读(115)  评论(0编辑  收藏  举报