首页 > 编程 > Python > 正文

Python QT由登陆界面到主界面

2019-11-08 00:58:08
字体:
来源:转载
供稿:网友

      在使用Python QT开发界面的时候,会出现从登陆界面到主界面的一个切换问题。如下所示,用户输入用户名和密码后,如果用户名和密码匹配,则会跳转到主界面,此时登陆界面消失。

       首先需要定义自己需要的对话框,请参考:http://blog.csdn.net/lovelyaiq/article/details/55050580。在代码加入对话中加入对话框退出时的返回值,例如:accept(),reject()。

    def save_button_click(self):        global Current_user        Current_user=str(self.lineEdit_name.text())        self.passwd_input=str(self.lineEdit_wd.text())        passwd_check=False        username_check=False        if not Current_user.endswith("@163.com"):            QtGui.QMessageBox.warning(self, "Error", u'请检查输入的用户名格式,需要以"@163.com"结尾',                                           buttons=QtGui.QMessageBox.Ok, defaultButton=QtGui.QMessageBox.Ok)        else:            username_check=True        if self.passwd != self.passwd_input and username_check:            QtGui.QMessageBox.warning(self, "Error", u'您输入的密码有误 !!!',                                           buttons=QtGui.QMessageBox.Ok, defaultButton=QtGui.QMessageBox.Ok)        else:            passwd_check=True        if username_check and passwd_check:            self.accept()           当用户点击登陆按钮时,软件会检测用户名和密码是否匹配,如果匹配,则返回accept(),在主程序中需要接受到这个返回值。

    if dialog.exec_()==QtGui.QDialog.Accepted:        ui = Ui()        ui.show()其中dialog.exec_()表示等待登陆界面退出,如果登陆界面退出时的返回值是QtGui.QDialog.Accepted,那么将会启动主界面。

注:在两个界面切换的过程中,使用到了登陆界面退出时的返回值,根据这个返回值判断是否启动主界面。关于exec_()的解释,文档的说明为:

Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表