PyQt5 installation and usage tutorial

1. Open Pycharm, create a new Project and name it PyQt5

2. Enter Setting->Project Interpreter to install the corresponding toolkit PyQt5, click Install Package

  

3. Continue to install the toolkit PyQt5-tools 

 

The following errors may be encountered:

 

It is because the library only supports python3.9 at present, and the current python compiler version 3.10 needs to re-download a compiler below python3.9

 

Fourth, configure parameters in Pycharm

1. Right-click "My Computer" in the file manager to pop up the shortcut menu, select "Properties" → "Advanced System Settings" to pop up the system properties dialog box

 2. Select "Advanced", click "Environment Variables" below, the environment variable setting box will pop up, select the "Path" variable in the system variables, as shown in the following figure:

3. Double-click the "Path" environment variable to enter the environment variable editing interface, click "Edit" to add the installation location of pyqt5-tools at the end, and click OK, as shown in the following figure:

 

4. Click "New" in the environment variable interface, and create a new variable named "QT_PLUGIN_PATH" in the system environment variable, as shown in the figure below:

 

Find the "plugins" folder and add the path to the system variables 

 

5. Configure Qt Designer, click "File" in the menu bar, a drop-down box will pop up, select "Setting", and the setting interface will pop up. Select "Tools" → "External Tools" in the setting interface, the operation of this part is shown in the figure below:

 

6. Click the "plus sign" button to create a new tool, and the tool configuration interface will pop up: fill in "Qt-Designer" in the "Name" column; fill in the Designer.exe file location in the "Program" column. My location here is: "D: \PyQt5\venv\Lib\site-packages\qt5_applications\Qt\bin" (need to be filled in according to the actual situation); fill in the Working directory: $FileDir$

 

 7. Click "Tools" in the menu bar, a drop-down box will pop up, select "External Tools", and a tool selection box will pop up. Select "Qt-Designer" and click, if the software interface of Qt Designer appears, it means the configuration is successful.

8. Configure PyUIC, add the PyUIC tool in the same way as above, click the "plus" button, fill in "PyUIC" in the Name column of the pop-up edit setting box; fill in the file path of the pyuic5.exe program in Program. Fill in the content in Arguments: $FileName$ -o $FileNameWithoutExtension$.py

Fill in the Working directory: $FileDir$

 

Tutorial after installation:

1. Open or create a new Python project, click "Tools" in the menu bar, select "External Tools", you can see the three tools set before, select "Qt Designer" to open the Qt design tool, the steps are shown in the figure below :

 

2. After opening the software, select "Main Window" in the pop-up guide interface, and then click the "Create" button to create a window interface, as shown in the figure below: 

 

3. Drag three "Push Buttons" from the control selection bar on the left side of the software interface to the design box in the middle, and double-click the buttons to modify the displayed characters in turn, as shown in the figure below:  

4. Drag two "Label" controls from the control selection bar on the left side of the software interface to the design box in the middle, as shown in the figure below:

 

 5. Click the pencil chart under "Resource Browser", and the edit box for creating a new qrc file will pop up

6. As shown in the figure below, click the New button to create a new qrc file, and click the + sign to add the file.

7. Add two pictures to the qrc resource file, and finally click "OK" to confirm.

 

8. Select the added label form, and select "Select Resource" in the "pixmap" column of the "text" attribute in the right attribute editing bar, as shown in the following figure:

9. Select the saved ui file in PyCharm, and use the "PyUIC" tool in "External Tools" under "Tools" to convert the file into the required py file.

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_41982551/article/details/127120490