一.使用qt creator 设置登录界面


主界面为之前设计的界面 from123.py
文章地址:三.listview或tableviw显示

二.导出ui文件为py文件

# from123.py 为导出 py文件 form.ui 为 qt creator创造的 ui 文件pyuic5 -o x:\xxx\Fromlogin20230809.py form.ui

三.python 显示登录界面和功能

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'd:\QtcreatorProject\pythonUI\form.ui'## Created by: PyQt5 UI code generator 5.15.9## WARNING: Any manual changes made to this file will be lost when pyuic5 is# run again.Do not edit this file unless you know what you are doing.import sysfrom PyQt5.QtWidgets import *from PyQt5.QtCore import*from PyQt5.QtSql import*from PyQt5.QtGui import*from PyQt5 import QtCore, QtGui, QtWidgetsfrom from123 import Ui_Testfrom Fromlogin20230809 import Ui_login_MainWindow_2#登录界面class login_window(QWidget):def __init__(self,parent=None):super().__init__(parent)self.ui = Ui_login_MainWindow_2()self.ui.setupUi(self)# 固定大小self.setFixedSize(300, 150)# 设置窗口名self.setWindowTitle("登录") self.ui.lineEdit.setText('admin')self.ui.lineEdit_2.setText('admin12345')#连接槽self.ui.pushButton.clicked.connect(self.login_button)def login_button(self):if self.ui.lineEdit.text()=="":QMessageBox.warning(self, '警告', '密码不能为空,请输入!')return None # ifself.password == self.lineEdit.text():print(self.ui.lineEdit.text(),self.ui.lineEdit_2.text())# if (self.lineEdit.text()== self.Password) and self.lineEdit_2.text()== self.admin:if (self.ui.lineEdit.text()== 'admin') and self.ui.lineEdit_2.text()== 'admin12345':# Ui_Main = Open_Camera()# 生成主窗口的实例# 1打开新窗口Ui_Main.show()# 2关闭本窗口self.close()else:QMessageBox.critical(self, '错误', '密码错误!')self.lineEdit.clear()return None#主界面class QmyMainWindow(QWidget):def __init__(self,parent=None):super().__init__(parent)self.ui = Ui_Test()self.ui.setupUi(self)def Update(self):# // 生成一个四行两列的模型self.TableModel = QStandardItemModel()# 表头self.TableModel.setHorizontalHeaderLabels(['a','b','c'])for row in range(4):for column in range(2):item = QStandardItem(str(row))# 设置每个位置的文本值self.TableModel.setItem(row, column, item)self.ui.tableView.setModel(self.TableModel)def on_listWidget_customContextMenuRequested(self,pos):##右键快捷菜单策略情况menuList=QMenu(self)#创建菜单menuList.addAction(self.ui.actionsa) menuList.exec(QCursor.pos())#显示菜单if __name__ == "__main__":QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)#自适应分辨率 app = QtWidgets.QApplication(sys.argv)window = login_window()Ui_Main = QmyMainWindow(None)# 生成主窗口的实例window.show() sys.exit(app.exec_())

四.结果

点击登录后显示主界面