Akik Look at that coder
Public account: Look at that code farmer
Today we talk about things and GUI (graphical user interface), may everyone is a stranger to the word GUI, touch it and our life very closely, like everyone on the phone every day, on the computer to see what is composed of each GUI interface, it cold code, the programmer through all sorts of beautiful interesting image presented to the user. Guis are everywhere.
Speaking of GUI, Qt must be introduced
Qt is a cross-platform C++ graphical user interface application development framework developed by the Qt Company in 1991. It can be used to develop both GUI programs and non-GUI programs, such as console tools and servers. Qt is an object-oriented framework that is easily extensible and allows component programming using special code-generating extensions (called meta-object compilers) and some macros.
Since Qt is so powerful, is it possible to use Qt to design GUI Windows when writing Python code in Pycham?
The answer is yes.
Because of user demand, PyQt came into being.
PyQt is a toolkit for creating GUI applications. It is a successful fusion of the Python programming language and the Qt library.
PyQt implements a set of Python modules. It has over 300 classes and nearly 6,000 functions and methods. It is a multi-platform toolkit that runs on all major operating systems, including UNIX, Windows and Mac.
How do I install PyQt on Pycharm?
The following tweet explains it in detail.
Preparation Tools 1.Pycharm 2019.1.3 2.Anaconda 1.4.3(Python 3.6.0)
1. PyQt installed
The PIP installation is used here. Open the Anaconda prompt, in the Anaconda installation directory, and run the following command:
1.pip install sip // This is a support package provided by pyQt developers
2.pip install PyQt5 -i https://pypi.douban.com/simple
3.pip install PyQt5-tools -i https://pypi.douban.com/simple
Copy the code
1. Run Command 1, as shown in The figure
2. Run command 2, as shown in The figure
3. Run Command 3, as shown in The figure
Install in your own directory \Anaconda3\Lib\site-packages
With the above steps successfully completed, the PyQt installation is about halfway there.
2. Configuration Pycharm
The main thing here is to add two External tools to Pycharm
“Qt Designer” and “Pyuic”.
The former is used to open the Qt graphical interface for UI editing, while the latter is used to convert the generated.ui file to.py file so that it can be run.
1. Create Qt Designer
Under the new project
File->Settings->Tools->External Tools
Click the plus sign:
Name: Self-definable Suggestions are as follows: Qt Design program: XXX\anaconda\Lib\site-packages\ PyQt5_tools \designer.exe this is the installation path of Qt Designer. Directory: XXX\anaconda\Lib\site-packages\ pyQt5_toolsCopy the code
2. Create Pyuic
Under the new project
File->Settings->Tools->External Tools
Click the plus sign:
Name: Self-definable Suggestions are as follows: Exe parameter: -m pyqt5.uic. Pyuic $FileName$-o $FileNameWithoutExtension$.py Directory: $FileDir$Copy the code
3. The test
1. After completing the preceding steps, open Qt in PyCharm
Tools->External Tools->Qt Designer
This is the purpose of the first two steps:
2. Click on the Qt Designer. If everything works, the following edit screen will be displayed:
3. Select Main Windows, Create
Select a label in the Widget Box on the left and drag it into the window, naming it ceremonially Hello World.
4. Select Save. You are advised to Save it in the Pycharm project directory.
Go back to Pycharm and you’ll have a.ui file in the directory tree
5. Right-click the file and choose External Tools >PyUIC
At this point, hopefully, a.py file will be generated
If not, an error will be reported, as shown
Pycharm reported this error because Anaconda’s Python file lacks python3.dll
In this case, you need to go to the Python website to download your own Python version of Anaconda
Website link:
www.python.org/downloads/w…
Open the download folder and copy the python. DLL file
Copy and paste the file or replace it with Anaconda’s python.exe folder
Restart Pycharm and perform Step 5 to remove the error and generate the corresponding.py file
If you find this helpful:
1. Click “like” to support it, so that more people can see this article
2, pay attention to the public number: look at that code farmers, we study together and progress together.
This article is participating in the “Nuggets 2021 Spring Recruitment Campaign”, click to see the details of the campaign