Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件

  • 个人使用环境
  • 安装过程
    • 1. 安装PyQt5
    • 2. 安装pyqt5-tools
    • 3. 查看
    • 4. 创建环境变量
  • 配置过程
    • 1. 打开Pycharm
    • 2. 配置QtDesigner
    • 3. 配置pyuic5
    • 4. 配置pyrcc5
  • 操作过程
    • 1. 打开Pycharm中的Tools
    • 2. 创建.ui文件,并保存在工程目录下
    • 3. 在Pycharm工程中找到相应.ui文件
    • 4. 选中.ui文件右击,按下图操作点击pyuic5
    • 5. .ui转换成.py

个人使用环境

本人使用环境:
win 8
python 3.8
pycharm 2019.xx.xx

安装过程

1. 安装PyQt5

使用镜像源快速安装PyQt5:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyQt5

Python镜像源使用教程

2. 安装pyqt5-tools

使用镜像源快速安装pyqt5-tools:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyqt5-tools

Python镜像源使用教程

最好连这几个库都安装一下SIP、PyInstaller、PyQt5-sip

3. 查看

安装完PyQt5、pyqt5-tools后到Python的安装目录中查看,路径因人而异。例如:
D:\Programs\Python\Python38\Lib\site-packages
查看是否存在PyQt5、pyqt5-tools文件夹,并且在pyqt5-tools下的Qt\bin下是否存在designer.exe
若点击designer.exe存在以下报错,说明未创建环境变量!

This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第1张图片

4. 创建环境变量

在环境变量中的系统变量新建

变量名 QT_QPA_PLATFORM_PLUGIN_PATH
变量值 D:\Programs\Python\Python38\Lib\site-packages\PyQt5\Qt\plugins
变量值为个人python的安装路径,具体因人而异!

创建完后再去相应目录下点击打开designer.exe
D:\Programs\Python\Python38\Lib\site-packages\pyqt5_tools\Qt\bin\designer.exe

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第2张图片

配置过程

1. 打开Pycharm

File ==> Settings ==> Tools ==> External Tools  点击“+” 进行创建

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第3张图片
Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第4张图片

2. 配置QtDesigner

Name:QtDesigner
Program:D:\Programs\Python\Python38\Scripts\pyqt5designer.exe
#这里输入你的python安装路径下的Scripts\pyqt5designer.exe就好
Working directory:$ProjectFileDir$
点击OK

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第5张图片

3. 配置pyuic5

Name:pyuic5
Program:D:\Programs\Python\Python38\Scripts\pyuic5.exe
#这里输入你的python安装路径下的Scripts\pyuic5.exe就好
Arguments:$FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$
点击OK

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第6张图片

4. 配置pyrcc5

Name:pyrcc5
Program:D:\Programs\Python\Python38\Scripts\pyrcc5.exe
#这里输入你的python安装路径下的Scripts\pyrcc5.exe就好
Arguments:$FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第7张图片

操作过程

1. 打开Pycharm中的Tools

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第8张图片

2. 创建.ui文件,并保存在工程目录下

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第9张图片

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第10张图片

3. 在Pycharm工程中找到相应.ui文件

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第11张图片

4. 选中.ui文件右击,按下图操作点击pyuic5

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第12张图片

5. .ui转换成.py

Python3.8+PyQt5+pyqt5-tools+Pycharm配置+将ui文件转py文件_第13张图片

你可能感兴趣的:(Python,#,Qt)