打开File->settings->Tools->External Tools
程序:D:\python3.7\Lib\site-packages\qt5_applications\Qt\bin\designer.exe//安装包的时候回自动下载,直接在包文件夹中找
工作目录:$FileDir$
程序:D:\python3.7\python.exe//工具自己配置填写
实参:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
工作目录:$FileDir$
Tools->External Tools->QtDesigner
此时需要将untitled.ui文件转换为.py文件,方便pycharm查阅,右键选择External Tools,选择pyuic ,将其转换,转换后可以在左侧看见untitled.py
生成的文件不能显示,需要调用
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setObjectName("widget")
self.horizontalLayout.addWidget(self.widget)
self.widget_2 = QtWidgets.QWidget(self.centralwidget)
self.widget_2.setObjectName("widget_2")
self.comboBox = QtWidgets.QComboBox(self.widget_2)
self.comboBox.setGeometry(QtCore.QRect(330, 30, 171, 22))
self.comboBox.setObjectName("comboBox")
self.comboBox_2 = QtWidgets.QComboBox(self.widget_2)
self.comboBox_2.setGeometry(QtCore.QRect(330, 60, 171, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_3 = QtWidgets.QComboBox(self.widget_2)
self.comboBox_3.setGeometry(QtCore.QRect(330, 90, 171, 22))
self.comboBox_3.setObjectName("comboBox_3")
self.label = QtWidgets.QLabel(self.widget_2)
self.label.setGeometry(QtCore.QRect(260, 40, 54, 12))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.widget_2)
self.label_2.setGeometry(QtCore.QRect(260, 70, 54, 12))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.widget_2)
self.label_3.setGeometry(QtCore.QRect(260, 100, 54, 12))
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.widget_2)
self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 2)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.label_2.setText(_translate("MainWindow", "TextLabel"))
self.label_3.setText(_translate("MainWindow", "TextLabel"))
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
mainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow() # 这个是类名,名字根据自定义的情况变化
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())