修的了电脑 敲得了代码
     写得了前端 稳得住后端

PyQt5—继承界面类

通过PyUIC生成的界面类代码,每次更新页面都会变化,所以不要在生成的ui代码中添加自己的代码。

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

# Form implementation generated from reading ui file ‘test.ui’
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
     def setupUi(self, Dialog):
          Dialog.setObjectName("Dialog")
          Dialog.resize(400, 300)
          self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
          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(Dialog)
          self.buttonBox.accepted.connect(Dialog.accept)
          self.buttonBox.rejected.connect(Dialog.reject)
          QtCore.QMetaObject.connectSlotsByName(Dialog)

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

新建Mywindow类,继承生成的Ui_Dialog类

class Mywindow(QDialog,Ui_Dialog):
       def __init__(self,parent=None):
            super(Mywindow, self).__init__(parent)
            self.setupUi(self)

生成应用->展示界面->等待程序退出消息

if __name__ == '__main__' :
   app = QApplication(sys.argv)
   dlg = Mywindow()
   dlg.show()
   sys.exit(app.exec())
未经允许不得转载:流云溪|码农 » PyQt5—继承界面类

相关推荐

  • 暂无文章

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址