【PyQt5】PyQt5 development environment

First, use Anaconda to create a virtual environment (named qt here) to isolate it from other projects.
Python version 3.7.11
Insert image description here

1. Install PyQt5

Applicable to windows,
first execute the following two instructions to install the relevant libraries of pyqt5

# 第一条
pip install PyQt5 -i https://pypi.douban.com/simple
# 第二条
pip install PyQt5-tools -i https://pypi.douban.com/simple

PyQt5 no longer provides commonly used Qt tools, 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 PyQt5-tools.

2. Configure External Tools in PyCharm

1、Qt Designer

Qt Designer is the implementation tool for the UI interface of the PyQt program. Using Qt Designer, you can drag and click to complete the GUI interface design.

First find it in the virtual environment directory of anaconda QT Designer.exe. My path here is:
G:\software\Anaconda3\envs\qt\Lib\site-packages\qt5_applications\Qt\bin
Insert image description here
open pycharm——>File——>settings——>Tools——>External Tools——> +
Insert image description here
fill in as shown in the figure below, Programthe path is as above Write the path, Working directoryfill in: $FileDir$, click OK
Insert image description here

2、PyUIC

PyUIC can convert .ui files generated by Qt Designer into py files.

First find pyuic5.exe, my path here is:
G:\software\Anaconda3\envs\qt\Scripts\pyuic5.exe
Then fill it in according to the picture below, where the Argumentswriting $FileName$ -o $FileNameWithoutExtension$.py
Insert image description here
tool is configured.

3. Test

This step tests whether the environment is configured successfully.

Right-click the project folder——>External Tools——> Qt Designer
Insert image description here
to open the Qt Designer interface, draw an interface, and save it as a .ui file. Right-click the .ui file
Insert image description here
in pycharm ——>External Tools——> PyUIC
Insert image description here
in the same A py file with the same name will be generated in the directory
Insert image description here

Then create a new py file, write the following code, and run:

import sys
import test
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow

app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = test.Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())

Insert image description here
It now runs successfully and the environment installation is complete.

Guess you like

Origin blog.csdn.net/iiinoname/article/details/122340505