import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QProgressBar, QLabel, QLineEdit
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_label = QLabel("欢迎界面", self)
self.welcome_label.setGeometry(100, 100, 200, 30)
self.login_button = QPushButton("登录", self)
self.login_button.setGeometry(150, 200, 100, 30)
self.login_button.clicked.connect(self.show_user_panel)
self.user_panel_buttons = []
self.current_user = None
self.username_label = QLabel("用户名:", self)
self.username_label.setGeometry(150, 300, 100, 30)
self.username_input = QLineEdit(self)
self.username_input.setGeometry(250, 300, 200, 30)
self.password_label = QLabel("密码:", self)
self.password_label.setGeometry(150, 350, 100, 30)
self.password_input = QLineEdit(self)
self.password_input.setGeometry(250, 350, 200, 30)
self.password_input.setEchoMode(QLineEdit.Password)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.close()
def show_user_panel(self):
username = "admin" # 假设正确的用户名和密码是"admin"
password = "123456"
if self.current_user:
for button in self.user_panel_buttons:
button.show()
else:
if self.username_input.text() == username and self.password_input.text() == password:
self.current_user = username
for button in self.user_panel_buttons:
button.show()
def open_window_a(self):
self.window_a = WindowA(self)
self.window_a.show()
def open_window_b(self):
self.window_b = WindowB(self)
self.window_b.show()
class WindowA(BaseWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Window A")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(150, 200, 100, 30)
self.confirm_button.clicked.connect(self.start_progress_bar)
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(200, self.height() - 100, 400, 30)
def start_progress_bar(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_progress_bar)
self.timer.start(100) # 每100毫秒更新一次进度条
def update_progress_bar(self):
value = self.progress_bar.value()
if value < 100:
value += 10
self.progress_bar.setValue(value)
else:
self.timer.stop()
self.close()
self.parent().open_window_a2()
class WindowA2(BaseWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Window A2")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(150, 200, 100, 30)
self.confirm_button.clicked.connect(self.start_progress_bar)
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(200, self.height() - 100, 400, 30)
def start_progress_bar(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_progress_bar)
self.timer.start(100) # 每100毫秒更新一次进度条
def update_progress_bar(self):
value = self.progress_bar.value()
if value < 100:
value += 10
self.progress_bar.setValue(value)
else:
self.timer.stop()
self.close()
# 打开下一个窗口
class WindowA3(BaseWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Window A3")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(150, 200, 100, 30)
self.confirm_button.clicked.connect(self.start_progress_bar)
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(200, self.height() - 100, 400, 30)
def start_progress_bar(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_progress_bar)
self.timer.start(100) # 每100毫秒更新一次进度条
def update_progress_bar(self):
value = self.progress_bar.value()
if value < 100:
value += 10
self.progress_bar.setValue(value)
else:
self.timer.stop()
self.close()
# 所有程序结束
class WindowB(BaseWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Window B")
self.confirm_button = QPushButton("确认", self)
self.confirm_button.setGeometry(150, 200, 100, 30)
self.confirm_button.clicked.connect(self.start_progress_bar)
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(200, self.height() - 100, 400, 30)
def start_progress_bar(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_progress_bar)
self.timer.start(100) # 每100毫秒更新一次进度条
def update_progress_bar(self):
value = self.progress_bar.value()
if value < 100:
value += 10
self.progress_bar.setValue(value)
else:
self.timer.stop()
self.close()
# 打开下一个窗口
if __name__ == "__main__":
app = QApplication(sys.argv)
base_window = BaseWindow()
base_window.show()
sys.exit(app.exec())