pyqt5转python命令,及转化结果实例化方式

Myth丶恋晨 2021-12-22 23:17 226阅读 0赞

QtDesigner 保存的ui文件转化为python文件的命令

cmd 或者 powshell 中

  1. pyui5 -o 目标文件名.py 源文件名.ui

保存的ui文件

  1. // (xml) filename: 123.ui
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <ui version="4.0">
  4. <class>MainWindow</class>
  5. <widget class="QMainWindow" name="MainWindow">
  6. <property name="geometry">
  7. <rect>
  8. <x>0</x>
  9. <y>0</y>
  10. <width>800</width>
  11. <height>600</height>
  12. </rect>
  13. </property>
  14. <property name="windowTitle">
  15. <string>MainWindow</string>
  16. </property>
  17. <widget class="QWidget" name="centralwidget">
  18. <widget class="QPushButton" name="pushButton">
  19. <property name="geometry">
  20. <rect>
  21. <x>240</x>
  22. <y>150</y>
  23. <width>251</width>
  24. <height>191</height>
  25. </rect>
  26. </property>
  27. <property name="text">
  28. <string>PushButton</string>
  29. </property>
  30. </widget>
  31. </widget>
  32. <widget class="QMenuBar" name="menubar">
  33. <property name="geometry">
  34. <rect>
  35. <x>0</x>
  36. <y>0</y>
  37. <width>800</width>
  38. <height>26</height>
  39. </rect>
  40. </property>
  41. </widget>
  42. <widget class="QStatusBar" name="statusbar"/>
  43. </widget>
  44. <resources/>
  45. <connections/>
  46. </ui>

转化结果 + 实例化代码

  1. # -*- coding: utf-8 -*-
  2. # Form implementation generated from reading ui file '123.ui'
  3. #
  4. # Created by: PyQt5 UI code generator 5.11.3
  5. #
  6. # WARNING! All changes made in this file will be lost!
  7. from PyQt5 import QtCore, QtWidgets
  8. import sys
  9. class Ui_MainWindow(object):
  10. def setupUi(self, MainWindow):
  11. MainWindow.setObjectName("MainWindow")
  12. MainWindow.resize(800, 600)
  13. self.centralwidget = QtWidgets.QWidget(MainWindow)
  14. self.centralwidget.setObjectName("centralwidget")
  15. self.pushButton = QtWidgets.QPushButton(self.centralwidget)
  16. self.pushButton.setGeometry(QtCore.QRect(240, 150, 251, 191))
  17. self.pushButton.setObjectName("pushButton")
  18. MainWindow.setCentralWidget(self.centralwidget)
  19. self.menubar = QtWidgets.QMenuBar(MainWindow)
  20. self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
  21. self.menubar.setObjectName("menubar")
  22. MainWindow.setMenuBar(self.menubar)
  23. self.statusbar = QtWidgets.QStatusBar(MainWindow)
  24. self.statusbar.setObjectName("statusbar")
  25. MainWindow.setStatusBar(self.statusbar)
  26. self.retranslateUi(MainWindow)
  27. QtCore.QMetaObject.connectSlotsByName(MainWindow)
  28. def retranslateUi(self, MainWindow):
  29. _translate = QtCore.QCoreApplication.translate
  30. MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
  31. self.pushButton.setText(_translate("MainWindow", "PushButton"))
  32. // 此处为实例化方式
  33. if __name__ == '__main__':
  34. app = QtWidgets.QApplication(sys.argv)
  35. MainWindow = QtWidgets.QMainWindow()
  36. ui = Ui_MainWindow()
  37. ui.setupUi(MainWindow)
  38. MainWindow.show()
  39. sys.exit(app.exec_())

ret:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTAxMjEz_size_16_color_FFFFFF_t_70

发表评论

表情:
评论列表 (有 0 条评论,226人围观)

还没有评论,来说两句吧...

相关阅读

    相关 实例Class类的5方式

    Java的数据类型可以分为两类,即引用类型和原始类型。对于每种类型的对象,Java虚拟机会实例化不可变的java.lang. Class对象。它提供了在运行时检查对象属性的方法