当前位置: 移动技术网 > IT编程>脚本编程>Python > pyqt5实现登录界面的模板

pyqt5实现登录界面的模板

2019年06月03日  | 移动技术网IT编程  | 我要评论

甘健邑,黄金渔场 fx,雷州市人民政府

本文实例为大家分享了pyqt5登录界面的实现模板,供大家参考,具体内容如下

说明

本例,展示了通过登录界面打开主界面的实现方式。
其中,登录的账号与密码判断都比较简单,请大家根据自己需要,自行完善补充。

【如下代码,完全复制,直接运行,即可使用】

import sys
from pyqt5.qtwidgets import *
from pyqt5.qtcore import *
from pyqt5.qtgui import *
################################################
#######创建主窗口
################################################
class mainwindow(qmainwindow):
 def __init__(self, *args, **kwargs):
 super().__init__(*args, **kwargs)
 self.setwindowtitle('主界面')
 self.showmaximized()

################################################
#######对话框
################################################
class logindialog(qdialog):
 def __init__(self, *args, **kwargs):
 super().__init__(*args, **kwargs)
 self.setwindowtitle('登录界面')
 self.resize(200, 200)
 self.setfixedsize(self.width(), self.height())
 self.setwindowflags(qt.windowclosebuttonhint)

 ###### 设置界面控件
 self.frame = qframe(self)
 self.verticallayout = qvboxlayout(self.frame)

 self.lineedit_account = qlineedit()
 self.lineedit_account.setplaceholdertext("请输入账号")
 self.verticallayout.addwidget(self.lineedit_account)

 self.lineedit_password = qlineedit()
 self.lineedit_password.setplaceholdertext("请输入密码")
 self.verticallayout.addwidget(self.lineedit_password)

 self.pushbutton_enter = qpushbutton()
 self.pushbutton_enter.settext("确定")
 self.verticallayout.addwidget(self.pushbutton_enter)

 self.pushbutton_quit = qpushbutton()
 self.pushbutton_quit.settext("取消")
 self.verticallayout.addwidget(self.pushbutton_quit)

 ###### 绑定按钮事件
 self.pushbutton_enter.clicked.connect(self.on_pushbutton_enter_clicked)
 self.pushbutton_quit.clicked.connect(qcoreapplication.instance().quit)

 def on_pushbutton_enter_clicked(self):
 # 账号判断
 if self.lineedit_account.text() == "":
  return

 # 密码判断
 if self.lineedit_password.text() == "":
  return

 # 通过验证,关闭对话框并返回1
 self.accept()


################################################
#######程序入门
################################################
if __name__ == "__main__":
 app = qapplication(sys.argv)
 dialog = logindialog()
 if dialog.exec_()==qdialog.accepted:
 the_window = mainwindow()
 the_window.show()
 sys.exit(app.exec_())

本文如有帮助,敬请留言鼓励。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网