主调函数代码:
main.py
from PyQt5.QtWidgets import QWidget
from property import Ui_Widget
class MyWidget(QWidget):
def __init__(self):
super(MyWidget, self).__init__();
if __name__=='__main__':
import sys
from PyQt5.QtWidgets import QApplication
app=QApplication(sys.argv)
mw=MyWidget()
window=Ui_Widget()
window.setupUi(mw)
mw.show()
sys.exit(app.exec())
界面函数代码:
property.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Widget(object):
def setupUi(self, Widget):
Widget.setObjectName("Widget")
Widget.resize(927, 533)
self.pushButton = QtWidgets.QPushButton(Widget)
self.pushButton.setGeometry(QtCore.QRect(430, 250, 106, 29))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Widget)
self.pushButton.clicked.connect(Widget.close)
QtCore.QMetaObject.connectSlotsByName(Widget)
def retranslateUi(self, Widget):
_translate = QtCore.QCoreApplication.translate
Widget.setWindowTitle(_translate("Widget", "MyWidget"))
self.pushButton.setText(_translate("Widget", "PushButton"))
最后的运行效果: