PyQt5 Installation Guide (2)

Or refer to: https: //blog.csdn.net/u013044310/article/details/80777840 this article

 

PyQt5 + Pycharm installation and configuration of
the original sub-chapter Ju Kevin Posted on 2018-05-08 20:15:24 reading number 15112 Collection
launched

PyQt5 installation
anaconda installed before, which is contained pyqt, the search can be seen in the environment, but for the actual development, and not all of qt5 tool, you need to install it again.


Inside the cmd run:

pip install PyQt5 -i https://pypi.douban.com/simple
1

 

 

Install the popular Qt tools:

pip install PyQt5-tools -i https://pypi.douban.com/simple

 

 

In C: \ Users \ Administrator \ Anaconda3 \ Lib \ qt5 and kits can see the newly installed site-packages at path:

 

 


In order for the system can identify pyqt5-tools normally used commands, needs to be added to the system installation path environment variable path.

 

 

Type the path can be seen:

 

 

PyQt5 installation and testing
in Python input:

import PyQt5
1

 

 


That is not being given the right to view the PyQt5 depends module, see the following command:

help(PyQt5)

Configuring pycharm
create a new project, select an interpreter, the interpreter for the path where you installed Python, this time in the interpreter can see PyQt5 and pyqt5-tools are:

 

 


Then click on the external tools set up inside, click on the "+" to add Qt Designer and pyuic two options.

 

 


如下图为在新增Qt Designer窗口中的填写内容:

Name:可自己定义
program:Qt Designer的安装路径
parameter:不填
directory: $FileDir$

如下图:

 

 


如下图为在新增pyuic窗口中的填写内容:

Name:可自己定义
program:pyuic的安装路径
parameter:$FileName$ -o $FileNameWithoutExtension$.py

directory: $FileDir $

如下图:

 

 


完成后可在pycharm打开Qt Designer,这就是我们的目的:

 

 

此时打开Qt Designer,界面如下:

 

 

创建一个简单的界面后保存文件为test1.ui。

 

 

在pycharm的左侧可以看到生成的文件test1.ui

此时需要将test1.ui文件转换为.py文件,方便pycharm查阅,右键选择External Tools,选择pyuic ,将其转换:

 

 


转换后可在左侧看见:

 

 

双击test1.py文件即可查看:

但是此时的文件是不能运行的,还需要在其前后添加相应的模块:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow

XXXXXXXXXXX
XXXXX
XXXXX #为生成的代码段

if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())


运行此时的test1.py文件,就会看到刚才在Qt Designer中创建的文件了,如下图,实现了.ui 文件和.py 文件的相互转换。

 

 


————————————————
版权声明:本文为CSDN博主「章子雎Kevin」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhangziju/article/details/80243858

Guess you like

Origin www.cnblogs.com/logolbq/p/12116934.html