我已经创建了一个登录窗口,在用户输入正确密码之前,该窗口将一直保留。如果用户按右上角的“X”按钮,窗口应该消失。但是,即使用户输入不正确的密码,窗口也会消失。
代码:
代码:
class Login(QDialog):
def __init__(self,parent=None):
super(Login, self).__init__(parent)
self.grid = QGridLayout(self)
self.setGeometry(650, 350, 400, 150)
self.setFixedSize(400, 150)
self.UserLabels = QLabel(self)
self.UserLabels.setText('Login Number:')
self.grid.addWidget(self.UserLabels, 0, 0, 1, 1)
self.textName = QLineEdit(self)
self.grid.addWidget(self.textName, 0, 1, 1, 2)
self.buttonLogin = QPushButton('Submit', self)
self.buttonLogin.clicked.connect(self.closeGUI)
self.grid.addWidget(self.buttonLogin, 2, 0, 1, 3)
finish = QAction("Quit", self)
finish.triggered.connect(self.closeWin)
def closeGUI(self):
self.close()
return str(self.textName.text())
def closeWin(self):
self.close()
return 1
def handleLogin():
flag = 0
while flag == 0:
edit_params__QD = Login()
edit_params__QD.exec_()
if edit_params__QD.result() == 0:
password = edit_params__QD.closeGUI()
if password == '6':
flag = 1
else:
flag = 0
if edit_params__QD.closeWin() == 1:
flag = 1
if __name__ == '__main__':
app = QApplication(sys.argv)
handleLogin()