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设计】。

相关文章

Django实现跨域的2种方法

jsonp 方式一:指定返回方法 # 后端 def view(request): callback = request.GET.get('callback') return...

浅谈使用Python变量时要避免的3个错误

Python编程中经常遇到一些莫名其妙的错误, 其实这不是语言本身的问题, 而是我们忽略了语言本身的一些特性导致的,今天就来看下使用Python变量时导致的3个不可思议的错误, 以后在编...

浅谈pycharm出现卡顿的解决方法

浅谈pycharm出现卡顿的解决方法

使用pycharm时常出现   the IDE is running low on memory 的问题,表示pycharm这款IDE使用内存不足,需要在系统内存充足的情况下扩...

python 实现二维字典的键值合并等函数

这篇文章主要讲python中关于字典的一些具体操作,讲解的问题都是本人在实际编程中所遇到的问题,读者可以根据自己所遇到的问题具体问题具体分析。 (1) 二维字典的键值合并: 先提供一个应...

python中下标和切片的使用方法解析

下标 所谓下标就是编号,就好比超市中存储柜的编号,通过这个编号就能找到相应的存储空间。 Python中字符串,列表,元祖均支持下标索引。 例如: # 如果想取出部分字符,可使用下标...