一、创建项目
二、安装pyqt5库
三、配置PyCharm外部工具
打开File->settings->Tools->External Tools
1、配置QtDesigner
程序:D:\python3.7\Lib\site-packages\qt5_applications\Qt\bin\designer.exe//安装包的时候回自动下载,直接在包文件夹中找
工作目录:$FileDir$
2、配置PyUic
程序:D:\python3.7\python.exe//工具自己配置填写
实参:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
工作目录:$FileDir$
3、点击应用
四、使用工具
1、打开designer
Tools->External Tools->QtDesigner
2、放置控件
保存一下就会在工程中生成untitled.ui文件
3、生成py文件
此时需要将untitled.ui文件转换为.py文件,方便pycharm查阅,右键选择External Tools,选择pyuic ,将其转换,转换后可以在左侧看见untitled.py
4、显示生成的py文件
生成的文件不能显示,需要调用文章来源:https://www.toymoban.com/news/detail-644864.html
# -*- 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_())
五、效果展示
文章来源地址https://www.toymoban.com/news/detail-644864.html
到了这里,关于pycharm安装使用pyQt5的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!