# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
mainWindow.resize(487, 381)
self.centralwidget = QtWidgets.QWidget(mainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(300, 250, 111, 41))
self.pushButton.setObjectName("pushButton")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(10, 30, 221, 301))
self.textBrowser.setObjectName("textBrowser")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(10, 10, 54, 12))
self.label_3.setObjectName("label_3")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(250, 40, 225, 141))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget)
self.lineEdit_2.setText("")
self.lineEdit_2.setObjectName("lineEdit_2")
self.gridLayout.addWidget(self.lineEdit_2, 4, 1, 1, 1)
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.lineEdit.setText("")
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 1, 1, 1, 1)
self.label_2.raise_()
self.label.raise_()
self.lineEdit_2.raise_()
self.lineEdit.raise_()
mainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(mainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 487, 23))
self.menubar.setObjectName("menubar")
self.menugui = QtWidgets.QMenu(self.menubar)
self.menugui.setObjectName("menugui")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
mainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(mainWindow)
self.statusbar.setObjectName("statusbar")
mainWindow.setStatusBar(self.statusbar)
self.actioncaidan = QtWidgets.QAction(mainWindow)
self.actioncaidan.setObjectName("actioncaidan")
self.menugui.addAction(self.actioncaidan)
self.menubar.addAction(self.menugui.menuAction())
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(mainWindow)
# self.pushButton.clicked.connect(self.button_clickked)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
mainWindow.setTabOrder(self.lineEdit, self.lineEdit_2)
mainWindow.setTabOrder(self.lineEdit_2, self.pushButton)
mainWindow.setTabOrder(self.pushButton, self.textBrowser)
def retranslateUi(self, mainWindow):
_translate = QtCore.QCoreApplication.translate
mainWindow.setWindowTitle(_translate("mainWindow", "第一个GUI"))
self.pushButton.setText(_translate("mainWindow", "确认"))
self.label_3.setText(_translate("mainWindow", "信息栏:"))
self.label.setText(_translate("mainWindow", "请输入密码:"))
self.lineEdit_2.setPlaceholderText(_translate("mainWindow", "密码"))
self.label_2.setText(_translate("mainWindow", "请输入用户名:"))
self.lineEdit.setPlaceholderText(_translate("mainWindow", "用户名"))
self.menugui.setTitle(_translate("mainWindow", "文件"))
self.menu.setTitle(_translate("mainWindow", "关于"))
self.actioncaidan.setText(_translate("mainWindow", "caidan "))
import sys
from untitled import Ui_mainWindow
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
class MainCode(QMainWindow, Ui_mainWindow):
def __init__(self):
QMainWindow.__init__(self)
Ui_mainWindow.__init__(self)
self.setupUi(self)
# super().setupUi(mainWindow)
self.pushButton.clicked.connect(self.on_save) # 获取按钮点击
# 信号槽
def on_save(self):
password = self.lineEdit_2.text()
name = self.lineEdit.text()
print(password)
print(name)
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = QMainWindow() # 创建主窗口
w = MainCode() # 调用ui中的ui_mainWindow类,并赋值给w
w.setupUi(mainWindow) # 调用ui文件中的ui_mainWindow类中的setupUi函数,并传给主窗口mainWindow
mainWindow.show() # 显示窗口
sys.exit(app.exec_()) # 程序主循环