.ui转.py文件
- 先将生成的.ui文件转为.py文件
编辑.py文件
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtWidgets import QWidget
# 创建ui类
class Ui_Form(object):
# 创建ui的方法
def setupUi(self, Form):
Form.setObjectName("Form") # 窗口名称
Form.resize(400, 300) # 窗口大小
self.pushButton = QtWidgets.QPushButton(parent=Form) # 创建按钮
self.pushButton.setGeometry(QtCore.QRect(100, 120, 111, 41)) # 设置按钮位置
self.pushButton.setObjectName("pushButton") # 按钮名称
self.retranslateUi(Form) # 设置按钮名称
QtCore.QMetaObject.connectSlotsByName(Form) # 连接槽函数
# 设置按钮名称
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate # 翻译
Form.setWindowTitle(_translate("Form", "Form")) # 窗口名称
self.pushButton.setText(_translate("Form", "pyqt6按钮")) # 按钮名称
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
# 创建窗口
Form = QtWidgets.QWidget()
# 创建ui类
ui = Ui_Form()
# 调用ui类
ui.setupUi(Form)
# 显示窗口
Form.show()
sys.exit(app.exec())
- 效果如下: