pyside6窗口间传递信息,注册窗口信息返回登录窗口

from PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QLabel, QVBoxLayout, QLineEdit, QPushButton, QWidget

class RegisterWindow(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("Register Window")
        layout = QVBoxLayout()

        self.username_label = QLabel("Username:")
        self.username_edit = QLineEdit()
        layout.addWidget(self.username_label)
        layout.addWidget(self.username_edit)

        self.password_label = QLabel("Password:")
        self.password_edit = QLineEdit()
        layout.addWidget(self.password_label)
        layout.addWidget(self.password_edit)

        self.register_button = QPushButton("Register")
        self.register_button.clicked.connect(self.register)
        layout.addWidget(self.register_button)

        self.setLayout(layout)

    def register(self):
        # 注册逻辑处理...
        self.accept()

class LoginWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Login Window")
        layout = QVBoxLayout()

        self.username_label = QLabel("Username:")
        self.username_value_label = QLabel("")
        layout.addWidget(self.username_label)
        layout.addWidget(self.username_value_label)

        self.password_label = QLabel("Password:")
        self.password_value_label = QLabel("")
        layout.addWidget(self.password_label)
        layout.addWidget(self.password_value_label)

        self.register_button = QPushButton("Open Register Window")
        self.register_button.clicked.connect(self.open_register_window)
        layout.addWidget(self.register_button)

        central_widget = QWidget()
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

    def open_register_window(self):
        register_window = RegisterWindow(self)
        if register_window.exec() == QDialog.Accepted:
            username = register_window.username_edit.text()
            password = register_window.password_edit.text()
            self.username_value_label.setText(username)
            self.password_value_label.setText(password)

app = QApplication([])
login_window = LoginWindow()
login_window.show()
app.exec()

你可能感兴趣的:(Python,前端,python,qt)