pyqt5实现登录界面的模板

yipeiwu_com5年前Python基础

本文实例为大家分享了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_())

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python实现银行管理系统

python实现银行管理系统,供大家参考,具体内容如下 有的地方用的方法的比较复杂,主要是为回顾更多的知识 test1用来存类和函数 #test1.py import random...

Python的ORM框架中SQLAlchemy库的查询操作的教程

1. 返回列表和标量(Scalar) 前面我们注意到Query对象可以返回可迭代的值(iterator value),然后我们可以通过for in来查询。不过Query对象的all()、...

Python 实现毫秒级淘宝抢购脚本的示例代码

本篇文章主要介绍了Python 通过selenium实现毫秒级自动抢购的示例代码,通过扫码登录即可自动完成一系列操作,抢购时间精确至毫秒,可抢加购物车等待时间结算的,也可以抢聚划算的商品...

python pytest进阶之xunit fixture详解

前言 今天我们再说一下pytest框架和unittest框架相同的fixture的使用, 了解unittest的同学应该知道我们在初始化环境和销毁工作时,unittest使用的是set...

python的几种开发工具介绍

1 IDLE1.1 IDLE是python创初人Guido van Rossum使用python and Tkinter来创建的一个集成开发环境。要使用IDLE必须安装python an...