Building a qt development environment based on Python3

        I believe that most people who are new to Python visual programming use tkinter. tkinter is Python’s own library and can be used without installing a third-party library. In my Python column, there are also many visual interfaces designed based on tkinter. This article will try another Python visual programming library (pyqt). Unlike tkinter programming, qt visual programming requires the development environment to be configured in advance. This article will demonstrate in detail how to build a qt development environment.

1: Install Python

Python installation can be installed online or offline. You can go to the Python official website to find the corresponding installation package.

python official website:

Welcome to Python.org

python Chinese network

Python Windows version download | Python Chinese website official website 

 

After installation, open the cmd terminal and check the installation status:

 If there is no prompt, you need to configure the environment variables

        After installing Python, you need to configure the pip source. The default pip source is not in China. If you want to install a third-party library, it will be very slow. The installation may even fail due to the wall, so you need to change the pip source to a domestic one. There are several domestic ones. The sources are quite comprehensive, such as Alibaba Source, Tsinghua Source, etc.

In the personal directory of the C drive, create a new pip folder, and then create a new pip.ini configuration file under the folder.

Configure the source in the pip.ini file

[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host=mirrors.aliyun.com

Check whether the source is configured successfully

Two: Install PyQt5

1. Install sip package

pip install sip

 

2. Install PyQt5

pip install PyQt5

3. Install PySide2

pip install PySide2

Three: Pycharm configures PyQt5

1. Download and install pycharm

Download PyCharm: Python IDE for Professional Developers by JetBrains

2. Configure qt tool

Configure four external tools in Pycharm:

  • Qt Designer - Create a new .ui file
  • Edit In Designer - Edit existing .ui files
  • PyUIC - Convert .ui files to python code
  • PyRCC - Convert qrc files to python code

 

1>Configure Qt Designer

2>Configure Edit In Designer

3>Configure PyUIC

Arguments are filled in as follows:

-m PyQt5.uic.pyuic  $FileName$ -o $FileNameWithoutExtension$.py

 The working directory is filled in as follows:

$FileDir$

4>Configure PyRCC

Arguments are filled in as follows:

$FileName$ -o $FileNameWithoutExtension$_rc.py

Four: Practical test

 Jump out of qt tool

 Save the file, click PyUIC to convert this .ui file into python code, and the file untitled.py will be generated.

 Create the main python file and call the generated untitled.py

import sys
from PyQt5.QtWidgets import QApplication, QWidget
import untitled

if __name__ == '__main__':
    app = QApplication(sys.argv)

    Form = QWidget()

    ui = untitled.Ui_Frame()

    ui.setupUi(Form)

    Form.show()

sys.exit(app.exec_())

run:

Guess you like

Origin blog.csdn.net/qq_27071221/article/details/133461134