[PyQt5 desktop application development] 1. Visual environment construction steps (super detailed)

Table of contents

Install

Install PyQt5

Install PyQt5-tools

Install QT Designer

Verify successful installation

Developed using PyCharm

New Construction

Add external tools

helloworld project

About QT

This article mainly introduces how to install PyQt5 under the Window platform and how to develop and configure it under PyCharm.

Install

Install PyQt5

PyQt5There are two installation methods, one is to download the source code from the official website and the other is to use pipinstallation.

Here I recommend everyone to use pipinstallation. Because it will automatically select the appropriate PyQt5version based on your Python version, if you manually download the source code and install it, you will inevitably make a selection error. It is recommended to use a more secure installation method.

 pip3 install PyQt5 

In addition, if your network access to the external network is not very good, it is recommended to use Douban's mirror download, otherwise it will be very slow or the installation will fail.

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

Install PyQt5-tools

PyQt5Commonly used Qt tools are no longer provided, such as the graphical interface development tool Qt Designer and the international translation tool Liguist. If these are used in development, you must install the Qt tools yourself.

Here we still use script installation.

 pip install PyQt5-tools

Or use the mirror download:

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

Install QT Designer

        In addition, windowthe platform is PyQt-toolsinstalled by default QT Designer.exe.

Verify successful installation

Execute the following code:

 import sys
 from PyQt5.QtWidgets import QWidget, QApplication
 ​
 app = QApplication(sys.argv)
 widget = QWidget()
 widget.resize(640, 480)
 widget.setWindowTitle("Hello, PyQt5!")
 widget.show()
 sys.exit(app.exec())

If no error is reported and a window titled "Hello, PyQt5!" pops up, the installation is successful.

Developed using PyCharm

The installation PyCharmwill not be explained here. Just click "Next" each time and it will be installed by default.

What I installed here is the community version.

 After the installation is successful, open PyCharmLet's set up two extern tools.

  • Open QT Designer through PyCharm

  • xxx.uiConvert file to xxx.pyfile via PyCharm

Let’s fully explain this part by creating a new project.

New Construction

For example, let's create a new hellowordproject. Select File->New Project

New project name:helloworld

Environment managers such as Pipenv, Virtualenv, and are not used here .Conda

 Python` version can be specified. Currently I am using `Python3.9

The interface after successful creation:

Add external tools

PyCharm->File->Settings->Tools->External Tools

Then select "+"

Here is a screenshot after I added it successfully

Let’s add itQT Designer first , you can refer to the screenshot settings.

  • "Name": This can be customized

  • "Program": The installation directory of "designer.exe" is selected. For details, please refer to the QT Designer section.

  • "Working directory": Configure according to the actual situation. Here I use macros directly.$FileDir$

Add toPyuic

  • "Name": This can be customized

  • "Program": Select the installation directory of "pyuic5.exe"

  • "Arguments":$FileName$ -o $FileNameWithoutExtension$.py

    • It means converting the selected xxx.uifile into xxx.pya file with the same name

    • What needs special attention is that you need to right-click and select the corresponding file when executing xxx.ui, otherwise an error will occur.

  • "Working directory": Configure according to the actual situation. Here I use the macro $FileDir$ directly.

helloworld project

New new.uifile

Click Create

The interface after successful creation

Add a Label

Enter helloworld

Make the font bigger

Save ui file

Here I namedhelloworld.ui

keep

Files PyCharmcan be seen inhelloworld.ui

Convert helloworld.uithe file to helloworld.py file.

Again, be sure to select uithe file you are using to convert.

Be sure to select the corresponding ui file

New helloworld.pyfiles can be seen

Run to see the final effect.

The interface after running

About QT

QT SDKIncludes Qtlibraries, libraries , Qt Creator IDEand Qt-toolslibraries, all in one easy-to-install package.

Qt CreatorUsers do not need a separate Qt Designerprogram, but there are many Qtusers who do not use it Qt Creator. At this time ui, they can only use it to edit files Qt Designer.

Guess you like

Origin blog.csdn.net/m0_60318025/article/details/130784138