Dec-23-2019, 09:53 AM
An Example for a login
from PyQt5 import QtWidgets class Login(QtWidgets.QDialog): def __init__(self, parent=None): super(Login, self).__init__(parent) self.textName = QtWidgets.QLineEdit(self) self.textName.setPlaceholderText("User name") self.textPass = QtWidgets.QLineEdit(self) self.textPass.setPlaceholderText("Password") self.buttonLogin = QtWidgets.QPushButton('Login', self) self.buttonLogin.clicked.connect(self.handleLogin) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(self.textName) layout.addWidget(self.textPass) layout.addWidget(self.buttonLogin) def handleLogin(self): if (self.textName.text() == 'foo' and self.textPass.text() == 'bar'): self.accept() QtWidgets.QMessageBox.information( self, 'Info', 'user and password ok') else: QtWidgets.QMessageBox.warning( self, 'Error', 'Bad user or password') class Window(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Window, self).__init__(parent) if __name__ == '__main__': import sys app = QtWidgets.QApplication(sys.argv) login = Login() if login.exec_() == QtWidgets.QDialog.Accepted: window = Window() window.show() sys.exit(app.exec_())