我 的 个 人 主 页: 失心疯的个人主页
入 门 教 程 推 荐 : Python零基础入门教程合集
虚 拟 环 境 搭 建 : Python项目虚拟环境(超详细讲解)
PyQt5 系 列 教 程: Python GUI(PyQt5)文章合集
Oracle数据库教程: Oracle数据库文章合集
优 质 资 源 下 载 : 资源下载合集
QTDesigner 简单使用
# 1. 打开cmd
win + r —— cmd —— 回车
# 2. 通过cd 命令,进入pyuic5.exe所在的目录(虚拟环境)
# 进入E盘
e:
# 进入目录
cd E:\Projecs\PyQt5\.venv\Scripts
# 调用转换工具, 输入pyuic5,按tab键。然后输入转换命令
pyuic5.exe E:\Projecs\PyQt5\login.ui -o E:\Projecs\PyQt5\login.py
# 用pyuic5.exe将文件输出(-o:output)为指定文件
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'E:\Projecs\PyQt5\login.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.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(361, 191)
Form.setStyleSheet("")
self.layoutWidget = QtWidgets.QWidget(Form)
self.layoutWidget.setGeometry(QtCore.QRect(50, 60, 259, 96))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget)
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
self.pushButton.setStyleSheet("background-color: rgb(255, 170, 127);")
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.label.setBuddy(self.lineEdit)
self.label_2.setBuddy(self.lineEdit_2)
self.retranslateUi(Form)
self.pushButton.clicked.connect(Form.Slot_login) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Form)
Form.setTabOrder(self.lineEdit, self.lineEdit_2)
Form.setTabOrder(self.lineEdit_2, self.pushButton)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "账号(&N):"))
self.label_2.setText(_translate("Form", "密码(&P):"))
self.pushButton.setText(_translate("Form", "登录"))
import login_rc
ModuleNotFoundError: No module named 'login_rc'
pyuic5.exe E:\Projecs\PyQt5\login.ui -o E:\Projecs\PyQt5\login-2.py -x
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'E:\Projecs\PyQt5\login.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.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(361, 191)
Form.setStyleSheet("")
self.layoutWidget = QtWidgets.QWidget(Form)
self.layoutWidget.setGeometry(QtCore.QRect(50, 60, 259, 96))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget)
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
self.pushButton.setStyleSheet("background-color: rgb(255, 170, 127);")
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.label.setBuddy(self.lineEdit)
self.label_2.setBuddy(self.lineEdit_2)
self.retranslateUi(Form)
self.pushButton.clicked.connect(Form.Slot_login) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Form)
Form.setTabOrder(self.lineEdit, self.lineEdit_2)
Form.setTabOrder(self.lineEdit_2, self.pushButton)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "账号(&N):"))
self.label_2.setText(_translate("Form", "密码(&P):"))
self.pushButton.setText(_translate("Form", "登录"))
import login_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
ModuleNotFoundError: No module named 'login_rc'
pyrcc5.exe E:\Projecs\PyQt5\login.qrc -o E:\Projecs\PyQt5\login_rc.py
AttributeError: 'QWidget' object has no attribute 'Slot_login'
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login.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.
from PyQt5 import QtCore, QtGui, QtWidgets
import qrc_login_rc
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(361, 191)
Form.setStyleSheet("")
self.layoutWidget = QtWidgets.QWidget(Form)
self.layoutWidget.setGeometry(QtCore.QRect(50, 60, 259, 96))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget)
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
self.pushButton.setStyleSheet("background-color: rgb(255, 170, 127);")
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.label.setBuddy(self.lineEdit)
self.label_2.setBuddy(self.lineEdit_2)
self.retranslateUi(Form)
self.pushButton.clicked.connect(Form.Slot_login)
QtCore.QMetaObject.connectSlotsByName(Form)
Form.setTabOrder(self.lineEdit, self.lineEdit_2)
Form.setTabOrder(self.lineEdit_2, self.pushButton)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "账号(&N):"))
self.label_2.setText(_translate("Form", "密码(&P):"))
self.pushButton.setText(_translate("Form", "登录"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
Form.Slot_login = lambda: print('按钮被点击了')
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
$FileName$ -o $FileNameWithoutExtension$.py -x