The last article explained how to install and configure a Python-related development environment. Now, what project do you want to start? After thinking for several times, I decided to make a simple calculator.

To make calculators, it is necessary to use related GUI libraries, such as Swing in Java. So I started looking for information about Python GUI, and found that there were quite a few Python libraries, which made me very happy and immediately wanted to try every GUI library.

After a lot of sifting and comparison, I found that in Python, the GUI library is better with these three

1, Tkinter, this module is the Python official standard GUI library, from the official, performance is better, support Windows, Unix, Macintosh currently mainstream operating systems;

2, wxPython, wxPython is an open source software, is a set of excellent Python GUI graphics library, easy to use, the latest version is 4.0.7. It runs on Windows, Mac, Linux and other Unix-like systems.

PyQt5 is a very powerful GUI graphics library, you will love it.

Qt is a cross-platform set of C ++ libraries that implement high-level apis for accessing many aspects of modern desktop and mobile systems. These include location and location services, multimedia, NFC and Bluetooth connectivity, Chromium-based Web browsers, and traditional UI development. PyQt5 is a comprehensive set of Python bindings for Qt V5. It is implemented as over 35 extension modules that enable Python to be used as an alternative C ++ application development language on all supported platforms, including iOS and Android.

In the end, I chose PyQt5 to implement the calculator interface. There is no best, according to their actual choice for their best.

Example Modify a PIP image source

Since PIP’s default image source is a foreign network address, the download speed will be very slow, and may even fail.

This needs to be changed to the domestic mirror source

For example, in the Windows operating system, check whether there is a PIP folder in the C: Users** AppData\Roaming\ directory, create a folder named PIP, and create a pip.ini file in the PIP folder. Fill in the following information in the file

[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
timeout = 6000
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true

Copy the code

In this way, the mirror source of PIP is changed to the mirror source of Tsinghua University in China.

Of course, there are many mirror sources to choose, such as Ali Cloud, here according to their preferences.

Install PyQt5

Open CMD command tool as system administrator

Run PIP Install PyQt5 and PIP Install PyQt5-Tools respectively and wait until PyQt5 is installed

PyQt5 is configured in PyCharm

In PyCharm File | Settings | Tools | External Tools, click on the “+” to add, as shown in figure, here I am adding, QT Designer is PyQt5 interface editing Tools, PyUIC is a tool that converts page.ui files edited by PyQt5 into.py files.

For PyUIC configuration, see the figure.

Solutions:

The “F: \ Python \ Python38 \ Lib \ site – packages \ PyQt5 \ Qt \ plugins” copied into the path of “platforms” folder “F: \ Python \ Python38 \ Lib \ site – packages \ pyqt5_tools \ Qt \ bin” directory, replacing the original “platforms” folder, so you can run normally PyQt5 – tools designer tool.

Write calculator interface

After a few minutes of drag and drop interface, the calculator interface is completed. Pyuic tool to convert.ui file into.py file, as shown in the figure

The operation effect is shown below

At present, the main interface and click events done, and then to achieve the operation of addition, subtraction, multiplication and division.