formhello.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>90</x>
<y>60</y>
<width>281</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>Hello,everyHHOne!</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="margin">
<number>20</number>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>130</x>
<y>140</y>
<width>171</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
根据formhello.ui生成的ui_FormHello.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'formhello.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class ui_FormHello(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(90, 60, 281, 91))
font = QtGui.QFont()
font.setPointSize(17)
font.setBold(False)
font.setItalic(False)
font.setUnderline(True)
font.setWeight(50)
self.label.setFont(font)
self.label.setTextFormat(QtCore.Qt.AutoText)
self.label.setWordWrap(False)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(130, 140, 171, 41))
font = QtGui.QFont()
font.setPointSize(15)
self.pushButton.setFont(font)
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.label.setText(_translate("Form", "Hello,everyHHOne!"))
self.pushButton.setText(_translate("Form", "PushButton"))
demo2.py
##appMain1.py
##使用ui_FormHel1o.py文件中的类Ui_FormHello创建app
import sys
from PyQt5 import QtWidgets
from referencePackage.pyqt5Demos.ui_FormHello import ui_FormHello
app=QtWidgets.QApplication(sys.argv)
basewidget=QtWidgets.QWidget()#创建窗体的基类QWidget的实例
ui=ui_FormHello()
ui.setupUi(basewidget)#以basewidget作为传递参数,创建完整窗体
basewidget.show()
##ui.LabHello.setText("Hello,被程序修改")#可以修改窗体上标签的文字
sys.exit(app.exec_())