Social Icons

Friday, August 28, 2020

The GUI PyQt Library

1 - About PyQt5

PyQt is a library considered to be a link of the Python language with the Qt GUI toolkit, which can be quickly installed with the pip utility and implemented as a Python module. PyQt is a free software developed by the firm Riverbank Computing. It is available under conditions similar to earlier Qt versions and that means a variety of licenses, including the GNU General Public License (GPL) and the Commercial License, but not the GNU Lesser General Public License (LGPL). PyQt supports Microsoft Windows as well as various versions of UNIX, including Linux and MacOS (or Darwin). PyQt implements around 440 classes and over 6,000 functions and methods.

2 - Installation of PyQt5 and first program

2.1 - Installation of PyQt5

The PyQt5 library, can be easily installed via the pip utility:
pip3 install pyqt5
 
After installing the PyQt5 library, we need to install the auxiliary tools using the command prompt:
pip3 install pyqt5-tools

3 - First PyQt5 graphics window


To create a graphics window in PyQt5, we must:
  1. Import the system module: sys 
  2. Import the class that generates the application: QApplications from the PyQt5.QtWidgets package. 
  3. Import the QWidget class from the PyQt5.QtWidgets package 
  4. Create an application using the instance() method of the QApplication class 
  5. Create a window with the QWidget() method: root = QWidget()  
  6. Display the window using the show() method: root.show() 
  7. Run the application using the exec_() method: app.exec_() 
Code first graphics window with PyQt5
# imports necessary classes and modules 
import sys
from PyQt5.QtWidgets import QApplication, QWidget

# create a Qt application with QApplication
app = QApplication.instance()

# we check if there is already an instance of QApplication
if not app:
    # otherwise we create an instance of QApplication
    app = QApplication (sys.argv)

# We create a window using the QWidget object
root = QWidget ()

# we set a title to the window
root.setWindowTitle ("My first pyqt app")

# we set the window size
root.resize (500,250)

# we visualize the window
root.show ()

# execution of the application, execution allows you to manage events
app.exec_()
Which displays a nice window after execution:




Younes Derfoufi
my-courses.net

No comments:

Post a Comment

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (1) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (168) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) CSS-Cascading-Style-Sheets (4) Developpement Java (13) Differential Geometry (1) Django-Python-Framework (8) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) HTML (7) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (32) Python BeautifulSoup (1) Python For Data Science (2) Python-Books (6) Python-DVD-Training (1) Python-Exercises (138) Python-Framework (1) Python-IDE (1) Python-Modules (1) Python-pdf (2) Python-pyQt (1) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (1) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1) Wordpress (1)
 

Sample text

Sample Text

 
Blogger Templates