消息框一直在“闪烁”:s。它没有崩溃,但它只是不断地打开和重新打开。我怎样才能解决这个问题?在
self.retranslateUi(Login)
QtCore.QObject.connect(self.ExitButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Login.close)
QtCore.QObject.connect(self.LoginButton, QtCore.SIGNAL("clicked()"),self.get_value_from_user)
QtCore.QMetaObject.connectSlotsByName(Login)
Login.setTabOrder(self.LoginButton, self.UsernameEdit)
Login.setTabOrder(self.UsernameEdit, self.PasswordEdit)
Login.setTabOrder(self.PasswordEdit, self.ExitButton)
def get_value_from_user(self):
Correct_details = False
while Correct_details==False:
inputusername=self.UsernameEdit.text()
inputpassword=self.PasswordEdit.text()
cur.execute("SELECT password FROM tblStaff WHERE username='"+inputusername+"'")
password=str(cur.fetchone())
password=password[2:-3]
cur.execute("SELECT firstname FROM tblStaff WHERE username='"+inputusername+"'")
FirstName=str(cur.fetchone())
FirstName=FirstName[2:-3]
cur.execute("SELECT surname FROM tblStaff WHERE username='"+inputusername+"'")
Surname=str(cur.fetchone())
Surname=Surname[2:-3]
if str(password) == str(inputpassword):
self.msgBox1 = QMessageBox(QMessageBox.Information,'Successful', "Succesfully Logged in")
self.msgBox1.show()
Correct_details = True
else:
self.msgBox2 = QMessageBox(QMessageBox.Information, 'Warning', "The Username or Password you have entered is incorrect")
self.msgBox2.show()
你的程序逻辑是错误的。在}读取相同的登录详细信息,当然继续不正确,因此循环将永远运行,循环的每一次迭代,您都会弹出消息框说它们不正确。在
get_value_from_user()
方法中,有一行while Correct_details==False:
。这是导致故障的线路。一旦用户输入了错误的登录详细信息,他们就不能再次输入这些信息,您只需重复从self.UsernameEdit
和{上面提到的循环需要在代码中的其他地方(可能在调用
get_value_from_user
的方法中),允许用户重新输入用户名和密码。get_value_from_user()
方法可能应该返回变量Correct_Details
,以便调用方法可以决定是否再次向用户显示登录表单,还是继续。在相关问题 更多 >
编程相关推荐