import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QProgressBar
class BaseWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Base Window")
self.setGeometry(0, 0, 1440, 900)
self.setStyleSheet("background-color: lightblue;")
self.quit_button = QPushButton("退出", self)
self.quit_button.setGeometry(20, 20, 80, 30)
self.quit_button.clicked.connect(self.close)
self.welcome_button = QPushButton("欢迎界面", self)
self.welcome_button.setGeometry(100, 100, 200, 50)
self.welcome_button.clicked.connect(self.show_login_window)
self.login_button = QPushButton("用户登录界面", self)
self.login_button.setGeometry(100, 200, 200, 50)
self.login_button.clicked.connect(self.show_user_panel)
self.user_panel_buttons = []
for i in range(5):
button = QPushButton(f"按钮{i+1}", self)
button.setGeometry(0, 0, 200, 50)
button.move(self.width()//2 - button.width()//2, self.height()//2 - button.height()//2 + i*60)
button.hide()
self.user_panel_buttons.append(button)
self.current_user = None
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.close()
def show_login_window(self):
# 显示登录窗口的逻辑
pass
def show_user_panel(self):
# 用户验证成功后显示用户面板的逻辑
if self.current_user:
for button in self.user_panel_buttons:
button.show()
def confirm_button_clicked(self, index):
if index == 0:
self.show_progress_bar(self.open_window_a)
elif index == 1:
self.show_progress_bar(self.open_window_b)
# ... 其他按钮对应的操作
def show_progress_bar(self, callback):
progress_bar = QProgressBar(self)
progress_bar.setGeometry(self.width()//2 - 100, self.height() - 100, 200, 30)
progress_bar.setValue(0)
def update_progress():
nonlocal progress_bar
progress_bar.setValue(progress_bar.value() + 10)
if progress_bar.value() >= 100:
callback()
progress_bar.deleteLater()
timer = QTimer(self)
timer.timeout.connect(update_progress)
timer.start(100)
class WindowA(BaseWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Window A")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
self.confirm_button.clicked.connect(self.show_progress_bar_a2)
def show_progress_bar_a2(self):
self.show_progress_bar(self.open_window_a2)
def open_window_a2(self):
window_a2 = WindowA2()
window_a2.show()
self.close()
class WindowA2(BaseWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Window A2")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
self.confirm_button.clicked.connect(self.show_progress_bar_a3)
def show_progress_bar_a3(self):
self.show_progress_bar(self.open_window_a3)
def open_window_a3(self):
window_a3 = WindowA3()
window_a3.show()
self.close()
class WindowA3(BaseWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Window A3")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
self.confirm_button.clicked.connect(self.show_progress_bar_end)
def show_progress_bar_end(self):
self.show_progress_bar(self.close_all_windows)
def close_all_windows(self):
self.close()
class WindowB(BaseWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Window B")
# ... 其他窗口B的内容
if __name__ == "__main__":
app = QApplication(sys.argv)
base_window = BaseWindow()
base_window.show()
sys.exit(app.exec())