from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QDesktopWidget from PyQt5.QtCore import Qt from qfluentwidgets import PushButton, SubtitleLabel, Theme, setTheme import app.env as env from .about import AboutWidget class InitWindow(QWidget): def __init__(self, main_window): super().__init__() self.window = main_window if env.config.theme == "dark": setTheme(Theme.DARK) # 给窗口添加样式 self.setStyleSheet("background-color: #2E2E2E;") else: setTheme(Theme.LIGHT) # 设置窗口大小 self.resize(800, 600) # 设置窗口始终位于最上层 self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) # 居中显示 self.center_window() # 初始化布局 self.layout = QVBoxLayout(self) self.titleLabel = SubtitleLabel('初始化') self.start_button = PushButton('开始') self.start_button.clicked.connect(self.run) self.layout.addWidget(self.start_button) # 将组件添加到布局中 self.layout.addWidget(self.titleLabel) self.layout.addWidget(AboutWidget()) # 应用布局 self.setLayout(self.layout) def center_window(self): """将窗口居中显示""" screen = QDesktopWidget().screenGeometry() size = self.geometry() new_left = (screen.width() - size.width()) // 2 new_top = (screen.height() - size.height()) // 2 self.move(new_left, new_top) def run(self): self.window.show() self.close() if __name__ == "__main__": import sys app = QApplication(sys.argv) window = InitWindow() window.show() sys.exit(app.exec_())