Social Icons

Monday, March 29, 2021

import sys

from PyQt5.QtWidgets import QApplication, QWidget, QPushButton

def buttonAction():
    print("You clicked on the button !")


app = QApplication(sys.argv)
widget = QWidget()

myButton = QPushButton(widget)
myButton.setText("Click here !")
myButton.move(50 , 30)
myButton.clicked.connect(buttonAction)

widget.setGeometry(100, 100 , 320 , 200)
widget.setWindowTitle("Example of PyQt5 Button")
widget.show()
sys.exit(app.exec_())


Younes Derfoufi
my-courses.net
Install PyQt5 & First Program 'Hello World !'

1 - About PyQt5 Library

PyQt is a Python 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 this 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:

pip install pyqt5-tools 

2.2 - First PyQt5 graphics window

To create a graphics window in PyQt5, we must: 

  1. Import the system module: sys 
  2. Import the QApplication 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: win = QWidget () 
  6.  View the window using the show() method: win.show () 
  7.  Run the application using the exec_() method: app.exec_ ()
Code of first graphics window with PyQt5:

import sys
from PyQt5.QtWidgets import QApplication, QWidget 

# create a PyQt5 application
app = QApplication(sys.argv)

# create a QWidget object
win = QWidget()

# Make a window title
win.setWindowTitle("This is a first PyQt5 app !")

# define a geometry of the window
win.setGeometry(100 , 100 , 500 , 400)

# apply the show method to view the window
win.show()

sys.exit(app.exec_())

3 - First PyQt5 window according to the object approach

import sys
from PyQt5.QtWidgets import QApplication, QWidget 

class MyWindow(QWidget):
    
    def __init__(self , win ):
        super().__init__()
        self.win = win
        
    def build(self):
        self.win.setWindowTitle("PyQt5 from object approach")
        self.win.setGeometry(100 , 100 , 400 , 150)
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    root = QWidget()
    mywin = MyWindow(root)
    mywin.build()
    
    root.show()
    sys.exit(app.exec_())
Younes Derfoufi
my-courses.net


Python Exercises With Solutions

  1. Exercises on Python Strings
  2. Exercises on Python lists
  3. OOP Exercices with solutions
  4. Exercises on Python File I/O
  5. Python Dictionary Exercises
  6. Python Sets Exercises
  1. Python Arithmetic Exercises
  2. Equations & System Of Equations
  3. Polynomials and Functions
  4. Python Arithmetic Exercises 
  5. Numpy, Matplolib, Sympy , Scipy - Exercises
  6. Python Arithmetic Exercises
  1. Python GUI Tkinter Exercises



Younes Derfoufi

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (2) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (256) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) Bootstrap CSS (1) 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 (14) 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 (36) Python BeautifulSoup (1) Python For Data Science (2) Python PyQt (13) Python Reference (1) Python Source Code (3) Python-Books (6) Python-DVD-Training (1) Python-Exercises (297) Python-Framework (1) Python-IDE (1) Python-Kivy-Framework (2) Python-Modules (1) Python-pdf (2) Python-pyQt (1) python-temp (3) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (4) 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