首页 文章 精选 留言 我的

精选列表

搜索[模板语言],共10000篇文章
优秀的个人博客,低调大师

pyqt5 登录界面的实现模板(加强版)

说明 本例,在登录界面第一版的基础上,增加了主界面的注销功能和退出功能。 注销功能 # 动作一:注销 def on_printAction1_triggered(self): self.close() dialog = logindialog() if dialog.exec_()==QDialog.Accepted: the_window = MainWindow() self.windowList.append(the_window) #这句一定要写,不然无法重新登录 the_window.show() 退出功能 # 动作二:退出 def on_printAction2_triggered(self): self.close() 还是很简单的吧,好了,下面给出完整代码。 完整代码 【如下代码,完全复制,直接运行,即可使用】 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * ################################################ #######创建主窗口 ################################################ class MainWindow(QMainWindow): windowList = [] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('主界面') self.showMaximized() # 创建菜单栏 self.createMenus() def createMenus(self): # 创建动作 注销 self.printAction1 = QAction(self.tr("注销"), self) self.printAction1.triggered.connect(self.on_printAction1_triggered) # 创建动作 退出 self.printAction2 = QAction(self.tr("退出"), self) self.printAction2.triggered.connect(self.on_printAction2_triggered) # 创建菜单,添加动作 self.printMenu = self.menuBar().addMenu(self.tr("注销和退出")) self.printMenu.addAction(self.printAction1) self.printMenu.addAction(self.printAction2) # 动作一:注销 def on_printAction1_triggered(self): self.close() dialog = logindialog() if dialog.exec_()==QDialog.Accepted: the_window = MainWindow() self.windowList.append(the_window) #这句一定要写,不然无法重新登录 the_window.show() # 动作二:退出 def on_printAction2_triggered(self): self.close() # 关闭界面触发事件 def closeEvent(self, event): print(999999999) pass ################################################ #######对话框 ################################################ 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_()) 本文如有帮助,敬请留言鼓励。本文如有错误,敬请留言改进。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册