利用qt5设计登录界面
# -*- coding: utf-8 -*- from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtCore import Qt, pyqtSignal, QTimer import first1 import jinggao class Ui_Dialog_log(object): usr_id = "138" pwd = "138" def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(400, 300) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(12) Dialog.setFont(font) self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(120, 50, 161, 31)) self.lineEdit.setObjectName("lineEdit") self.lineEdit_2 = QtWidgets.QLineEdit(Dialog) self.lineEdit_2.setGeometry(QtCore.QRect(120, 110, 161, 31)) self.lineEdit_2.setObjectName("lineEdit_2") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(60, 50, 51, 31)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(60, 110, 61, 31)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(120, 230, 75, 23)) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Dialog) self.pushButton_2.setGeometry(QtCore.QRect(240, 230, 75, 23)) self.pushButton_2.setObjectName("pushButton_2") self.retranslateUi(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "账号登录")) self.label.setText(_translate("Dialog", "账号")) self.label_2.setText(_translate("Dialog", "密码")) self.pushButton.setText(_translate("Dialog", "登录")) self.pushButton_2.setText(_translate("Dialog", "取消")) import sys if __name__ == "__main__": # -*- coding: utf-8 -*- usr_id = "138" pwd = "138" #,encoding="utf-8" def log_in(): str1 = ui1.lineEdit.text() str2 = ui1.lineEdit_2.text() if (str1 == usr_id) & (str2 == pwd): print("账号密码正确") Widget1.close() Wid_first.show() else: Widget2.show() app = QtWidgets.QApplication(sys.argv) ##/***** Widget2 = QtWidgets.QWidget() ui2 = jinggao.Ui_Dialog() ui2.setupUi(Widget2) # 将Widget1与ui联系起来 ui2.retranslateUi(Widget2) ##警告模块 ##*****/ ##/***** Wid_first = QtWidgets.QMainWindow() main_first = first1.Ui_MainWindow() main_first.setupUi(Wid_first) ##主模块 ##*****/ ##/***** #登录模块 Widget1 = QtWidgets.QWidget() ui1 = Ui_Dialog_log() ui1.setupUi(Widget1) ui1.retranslateUi(Widget1) Widget1.show() ##*****/ ui1.pushButton.clicked.connect(log_in) # 登录键相应工作Widget1.show ui1.pushButton_2.clicked.connect(Widget1.close) # 取消键关闭登录页面 ui2.pushButton.clicked.connect(Widget2.close) # 警告页面按下后退出警告页面 main_first.pushButton_5.clicked.connect(Wid_first.close) sys.exit(app.exec_())
评论