Pyqt installation and a simple example

Source: Internet
Author: User
Tags print print
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:
  1. First install python2.7.3, if the installation directory is c: \ python27
  2. 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
  3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.