|
发表于 2024-3-23 08:24:02
|
显示全部楼层
非常抱歉,我遗漏了这个重要的功能。下面是经过修正的代码,包括判断用户名和密码是否正确以及按钮窗体的添加:import sysfrom PySide6.QtCore import Qt, QThread, Signalfrom PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QProgressBar, QMessageBoxclass BassWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("BassWindow") self.setGeometry(0, 0, 1440, 900) self.setStyleSheet("background-color: blue;") self.options_btn = QPushButton("选项调整", self) self.options_btn.move(self.width() - 150, self.height() - 80) self.options_btn.clicked.connect(self.open_options) self.exit_btn = QPushButton("退出", self) self.exit_btn.move(self.width() - 80, self.height() - 80) self.exit_btn.clicked.connect(self.close) self.welcome_label = QLabel(self) self.welcome_label.setAlignment(Qt.AlignCenter) self.welcome_label.setText("欢迎") self.welcome_label.setGeometry(0, 0, self.width(), self.height()) self.welcome_label.setStyleSheet("font-size: 48px;") self.username_label = QLabel("用户名:", self) self.username_label.move(self.width() / 2 - 100, self.height() / 2) self.username_input = QLineEdit(self) self.username_input.move(self.width() / 2, self.height() / 2) self.password_label = QLabel("密码:", self) self.password_label.move(self.width() / 2 - 100, self.height() / 2 + 50) self.password_input = QLineEdit(self) self.password_input.move(self.width() / 2, self.height() / 2 + 50) self.password_input.setEchoMode(QLineEdit.Password) self.progress_thread = ProgressThread() self.progress_thread.finished.connect(self.check_credentials) self.buttons_layout = QVBoxLayout() self.buttons_layout.addWidget(QPushButton("按钮1", self)) self.buttons_layout.addWidget(QPushButton("按钮2", self)) self.buttons_layout.addWidget(QPushButton("按钮3", self)) self.target_window = QWidget(self) self.target_window.setGeometry(self.width() / 2 - 150, self.height() / 2 - 100, 300, 200) self.target_window.setLayout(self.buttons_layout) self.target_window.hide() def show_welcome_animation(self): # 在这里实现欢迎界面的动画效果 pass def open_options(self): print("打开选项调整界面") def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.close() def open_target_window(self): self.target_window.show() def check_credentials(self): username = self.username_input.text() password = self.password_input.text() # 模拟验证用户名和密码是否正确 if username == "admin" and password == "123456": self.open_target_window() else: QMessageBox.warning(self, "提示", "用户名或密码错误!")class WindowA(BassWindow): def __init__(self): super().__init__() self.setWindowTitle("WindowA")class WindowB(BassWindow): def __init__(self): super().__init__() self.setWindowTitle("WindowB")class WindowC(BassWindow): def __init__(self): super().__init__() self.setWindowTitle("WindowC")class ProgressThread(QThread): finished = Signal() def run(self): for i in range(101): self.progress = i self.msleep(100) # 模拟耗时操作 self.finished.emit()if __name__ == "__main__": app = QApplication(sys.argv) window = BassWindow() window.show() sys.exit(app.exec())在上述代码中,我添加了一个`QMessageBox`用于显示用户名或密码错误的提示。在`check_credentials`方法中,模拟验证了用户输入的用户名和密码是否正确。如果正确,会调用`open_target_window`方法打开按钮窗体;如果错误,会弹出提示框。按钮窗体使用一个`QWidget`作为容器,位置居中,并添加了三个按钮。希望这次没有遗漏任何功能!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|