Install pyqt in Windows + Visual Studio as follows:
- Python-2.7.3.msi(Www.python.org/download)
- Sip-4.14.2.zip(Www. riverbankcomputing. co. uk/software/SIP/download)
- PyQt-Py2.7-x86-gpl-4.9.6-1.exe(Www. riverbankcomputing. co. uk/software/pyqt/download)
Installation Method:
- First install python2.7.3, if the installation directory is c: \ python27
- Compile and install sip to decompress sip-4.14.2.zip. If the decompressed directory is D: \ sip-4.14.2, run the command line cmd to enter the SIP directory and enter the command:
C: \ python27 \ python.exe D: \ sip-4.14.2 \ Configure. py
The above command is used to generate the MAKEFILE file.
Open the Visual Studio Command Prompt window, enter the SIP directory, and enter the command:
Nmake
Nmake install
- Install pyqt-py2.7-x86-gpl-4.9.6-1.exe and click Install.
A simple example:
Import sys
From pyqt4.qtgui import * APP = qapplication (SYS. argv) label = qlabel ("<font color = Red size = 72> <B> Hello pyqt! </B> </font> export your label.show()app.exe C _ (): Print print
- The first line imports the SYS module because the command line parameters in SYS. argv are required;
- The second line imports the qt gui module. In this example, qlabel is used;
- The fourth line creates a qapplication object and passes the command line parameter SYS. argv to it. Each pyqt GUI application requires a qapplication object;
- Create a qlabel object on the fifth line to display HTML text;
- The sixth line indicates that the label is to be displayed, but so far, the label is not actually displayed. It only enters the object event queue of qapplication and waits for display;
- The seventh line starts the event loop of the qapplication object (pyqt uses exec _ () to avoid conflicts with the python built-in exec (). Therefore, the label window is displayed until the program exits.
If the control contains Chinese characters, character encoding must be set. Otherwise, garbled characters may occur. For example, in the above example, if the label is changed to "Hello pyqt !", Garbled characters may occur and the following changes are required:
#-*-Coding: UTF-8 -*-
Import sysfrom pyqt4.qtgui import * APP = qapplication (SYS. argv) label = qlabel (U "<font color = Red size = 72> <B> Hello pyqt! </B> </font> specify the character set used in the first line of Character Set label.show(app.exe C _ (); add u before the string in the seventh line.
Pyqt installation and a simple example