Pyqt6 return value on self.close() command

Hi all, i’m writing a pyqt6 app and I create a windows with login request. I call the windows from main function and I would like that if login success then I close login windows and I open new windows. I attach a sample code and I would ask to look where I put comment #IF LOGIN SUCCESS THEN OPEN NEW WINDOWS# and #–>RETURN VALUE TO MAIN<–#

class LoginWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('Login')
        self.setWindowIcon(QIcon(''))
        self.window_width, self.window_height = 600, 200
        self.setFixedSize(self.window_width, self.window_height)

        layout = QGridLayout()
        self.setLayout(layout)

        labels = {}
        self.lineEdits = {}

        labels['Username'] = QLabel('Username')
        labels['Password'] = QLabel('Password')
        labels['Username'].setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
        labels['Password'].setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)

        self.lineEdits['Username'] = QLineEdit()
        self.lineEdits['Password'] = QLineEdit()
        self.lineEdits['Password'].setEchoMode(QLineEdit.EchoMode.Password)

        layout.addWidget(labels['Username'],            0, 0, 1, 1)
        layout.addWidget(self.lineEdits['Username'],    0, 1, 1, 3)

        layout.addWidget(labels['Password'],            1, 0, 1, 1)
        layout.addWidget(self.lineEdits['Password'],    1, 1, 1, 3)

        button_login = QPushButton('&Log In', clicked=self.checkCredential)
        layout.addWidget(button_login,                  2, 3, 1, 1)

        self.status = QLabel('')
        self.status.setStyleSheet('font-size: 25px; color: red;')
        layout.addWidget(self.status, 3, 0, 1, 3)

    def checkCredential(self):
        username = self.lineEdits['Username'].text()
        password = self.lineEdits['Password'].text()
        self.loginSuccess = False
        if usernameIndex = "test" and password == "test":
            self.loginSuccess = True
        elif usernameIndex < 0:
            self.loginSuccess = False
            self.status.setText('Account not found')
        if self.loginSuccess == True:
            time.sleep(1)
            #-->RETURN VALUE TO MAIN<--#
            self.close()
        else:
            self.status.setText('Password is incorrect')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    loginSuccess = False
    loginWindow = LoginWindow(loginSuccess)
    loginWindow.show()
    #IF LOGIN SUCCESS THEN OPEN NEW WINDOWS#
    mainwindow = mainWindows()
    mainWindow.show()

    try:
        sys.exit(app.exec())
    except SystemExit:
        print('Closing Window...')

many thanks in advance
best regards

With the code pattern you are using the LoginWindow I think you want to use dialog window.

A dialog will blocks until the user closes the window. See the Qt docs QDialog Class | Qt Widgets 6.8.0