栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pyqt5 登录界面的实现模板

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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_())

本文如有帮助,敬请留言鼓励。
本文如有错误,敬请留言改进。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/221030.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号