Sivo 悉见

3、py程序引入PyQt5生成的GUI程序

匿名 · 更新于 2018/3/3

PyUIC生成的py代码t1.py

# -*- coding: utf-8 -*-

Form implementation generated from reading ui file 't1.ui'

Created by: PyQt5 UI code generator 5.10.1

WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Myui(object):     def setupUi(self, Myui):         Myui.setObjectName("Myui")         Myui.resize(400, 300)         self.buttonBox = QtWidgets.QDialogButtonBox(Myui)         self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))         self.buttonBox.setOrientation(QtCore.Qt.Horizontal)         self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)         self.buttonBox.setObjectName("buttonBox")

        self.retranslateUi(Myui)         # self.buttonBox.accepted.connect(Myui.accept)         # self.buttonBox.rejected.connect(Myui.reject)         QtCore.QMetaObject.connectSlotsByName(Myui)

    def retranslateUi(self, Myui):         _translate = QtCore.QCoreApplication.translate         Myui.setWindowTitle(_translate("Myui", "Dialog"))


 
要引入t1.py的脚本文件  t2.py
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from t1 import Ui_Myui

class myprog(Ui_Myui):     def init (self, dialog):         Ui_Myui.init(self)         self.setupUi(dialog)

if name == 'main':     app = QtWidgets.QApplication(sys.argv)     dialog = QtWidgets.QDialog()

    test1 = myprog(dialog)     dialog.show()     sys.exit(app.exec_())