[PyQt introductory tutorial] PyQt5 environment to build and configure

  Getting Started tutorial series PyQt main purpose is to hope that through this series of course, you can use PyQt5 tools to quickly implement a simple interface development, including interface design, layout management, and business logic (signals and slots). It simply is PyQt5 can use tools to quickly draw a control neatly and orderly interface. PyQt Getting Started tutorial includes the following:

   Section 1: PyQt5 environment set up and configuration.

   Section 2: Use Qt Designer tool. Description tool achieved through a demand.

   Section 3: Layout Manager Qt Designer tool. How to interface controls neatly.

   Section 4: Layout Manager Qt Designer tool. How to interface controls neatly.

   Section 5: PyQt5 use the basic controls introduced

    In this paper, Section 1 PyQt5 environment set up and configuration. The main contents include:

  (1) version of the tool options, including Python and PyQt versions of the software version.

  (2) Python, PyQt5 Qt Designer and the installation tool. Qt Designer is a visual PyQt GUI tool set.

  (3) arranged on PyCharm the Qt Designer and PyUIC tools.

Select reason PyQt

 (1) PyQt can drag and drop interface development to achieve , rather than only code. Such interface to achieve efficiency is much higher.

 (2) Control rich. Cross-platform support.

 (3) convenient packaged and released. Pyinstaller can use packaged into a binary file. Python software running on the computer is not installed.

Select Python3 and PyQt5 reasons

  PyQt official website provides PyQt4 and PyQt5 two main versions. PyQt5 incompatible PyQt4. We recommended to choose PyQt5 reasons :

  (1) The official PyQt4 no longer a major update and maintain.

  (2) PyQt5 for some modules have been rebuilt. And better support for web PyQt5 ability.

  (3) PyQt5 support the new slot and a signal, easier to use.

    Select Python3 reasons : PyQt5 better support for Python3, available by default only supports Python3 official version of the installation package. If you use Python2, to compile their own, too much trouble.

Python3.X software installation and PyQt5

  (1) Python official website to download Python3.X 32 Wei latest version. Get the path: Python official website reason, download the 32-bit version of this is the use of Pyinstaller packaged software release exe can run 32-bit and 64-bit computers. If the 64-bit version, you can only run the 64-bit version computer.

  (2) Execute the downloaded pyhon software installation. Check the "Add Python3.7 to Path". Other way Next to complete the installation. Installed by default a key tool pip.

(3) pip tool mirroring configuration. Configuration is as follows:

        a, execute echo% HOMEPATH% to obtain the user's home directory in the cmd window, and create a pip directory in the directory.

        b, create pip.ini file in the directory pip. Remember, the suffix .ini format. And write the following in the file.

 

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com

 

        c、配置完成。执行pip install xlrd测试安装是否成功。如果失败,参考配置指导参考<Python开发环境搭建指导>检查。

PyQt5工具安装

  (1)使用pip工具安装PyQt5工具。执行pip install PyQt5

  (2)安装Qt Designer图形界面开发工具。执行pip install PyQt5-tools

工具安装完成后的路径在..\Python\Python37-32\Lib\site-packages

  (3)环境变量配置。将PyQt5-tools的安装目录添加到系统环境变量path。添加路径:我的电脑 -> 属性->高级->系统设置->高级->单击环境变量。在系统变量path添加PyQt5-tools完整路径。如下图所示:

 (4)打开cmd窗口,执行designer。其实也可以将designer.exe设置快捷家到桌面。

Qt Designer主界面如下:

PyCharm配置Qt Designer

  PyCharm是开发Python程序主流常用的IDE。为方便调用Qt Designer实现界面开发和编译相应完成,可以在PyCharm配置Qt Designer和PyUIC。

 (1)配置Qt Designer。PyCharm -> 菜单File -> Settings -> Tools -> External Tools -> +号,进行添加。 参数配置说明:

  Name:Qt Designer。方便记忆。实际可以任意取值。

  Program:designer.exe程序绝对路径。根据实际安装路径填写。

  Parameters:$FileDir$\$FileName$。固定取值。

  Working directory: $FileDir$。固定取值。

(2)配置PyUIC。该工具是用于将Qt Designer工具开发完成的.ui文件转化为.py文件。配置打开路径同Qt Designer。参数配置说明:

  Name:PyUIC。方便记忆。实际可以任意取值。

  Program:python.exe程序绝对路径。根据实际安装路径填写。

  Parameters:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py。固定取值。

  Working directory: $FileDir$。固定取值。

(3)测试Qt Designer和PyUIC配置是否成功。打开路径:菜单栏Tools -> External Tools ->Qt Designer/PyUIC

   点击Qt Designer,打开Designer程序主界面如下。将左侧Widget Box中Push button空间拖到主界面,双击空间修改名称为test。另存为名称work.ui。默认后缀就是.ui。

 打开PyUIC,自动完成work.ui文件的转换。生成文件名为work.ui。

  文件转换成功后,可以在project目录中查看。如下

  配置成功。完成

手工打开designer和转换.ui文件

  除了集成到Pycharm工具使用,也可以采用手工方式打开designer和通过命令转换.ui文件为.py问津。方法如下: 

(1)设置designer为桌面快捷方式。designer路径在${python安装目录}/Lib/site-packages/pyqt5_tools/designer.exe

  (2)假设designer.exe开发完成的界面文件为work.ui。切换到work.ui目录并执行如下命令转换:

        pyuic5  -o work.py work.ui

最后总结

  学习完本文课程,就可以完成PyQt5工具安装和配置。为PyQt5开发界面迈出了最重要的一步。下一节就可以开始通过Qt Designer工具实现界面开发了。

Guess you like

Origin www.cnblogs.com/linyfeng/p/11216494.html