Ciao a tutti,
sto creando un applicazione con pyqt6 e vorrei che una pagina qwidget di richiesta login ritornasse una variabile al main quando le credenziali sono corrette, in modo da poter aprire la finestra principale. é possibile?
un esempio: (guardare dove ho messo ‘’'----?….?----''')
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
loginSuccess = False
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()
if username = "test" and password == "test":
self.loginSuccess = True
if self.loginSuccess == True:
time.sleep(1)
self.close()
'''----->RETURN TO __MAIN__<------'''
else:
self.status.setText('Password is incorrect')
if __name__ == '__main__':
# don't auto scale when drag app to a different monitor.
# QApplication.setAttribute(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
loginSuccess = False
app = QApplication(sys.argv)
app.setStyleSheet('''
QWidget {
font-size: 25px;
}
QLineEdit {
height: 200px;
}
''')
loginWindow = LoginWindow()
loginWindow.show()
'''----->IF login success then open main windows<-----'''
try:
sys.exit(app.exec())
except SystemExit:
print('Closing Window...')