pyqt5实现登录界面的模板

yipeiwu_com6年前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写的一个wordpress的采集程序

用python写的一个wordpress的采集程序

在学习python的过程中,经过不断的尝试及努力,终于完成了第一个像样的python程序,虽然还有很多需要优化的地方,但是目前基本上实现了我所要求的功能,先贴一下程序代码: 具体代码如...

浅谈python中的面向对象和类的基本语法

浅谈python中的面向对象和类的基本语法

当我发现要写python的面向对象的时候,我是踌躇满面,坐立不安呀。我一直在想:这个坑应该怎么爬?因为python中关于面向对象的内容很多,如果要讲透,最好是用面向对象的思想重新学一遍前...

Python3.5.3下配置opencv3.2.0的操作方法

Python3.5.3下配置opencv3.2.0的操作方法

1.安装numpy 进入python安装目录的lib下的site-packages文件夹下打开cmd输入pip install numpy下载numpy NumPy系统是Python的...

TensorFlow基于MNIST数据集实现车牌识别(初步演示版)

TensorFlow基于MNIST数据集实现车牌识别(初步演示版)

在前几天写的一篇博文《如何从TensorFlow的mnist数据集导出手写体数字图片》中,我们介绍了如何通过TensorFlow将mnist手写体数字集导出到本地保存为bmp文件。 车牌...

对Python中创建进程的两种方式以及进程池详解

在Python中创建进程有两种方式,第一种是: from multiprocessing import Process import time def test(): whil...