PyQt Hello World
Last Updated :
26 Mar, 2020
There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library.
Installation :
pip install PyQt5
In this article we will see how to make simple PyQt5 application which print the message “Hello World !”
Code :
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "hellow world !" )
self .setGeometry( 0 , 0 , 300 , 300 )
self .label = QLabel( "Hello World !!" , self )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Explanation :
First of all we have created the Window
class which inherits QMainWindow
class. Within this class we can add widgets which will get displayed on main window, we have used setWindowTiltle
method to set title. setGeometry
method to set size and position of the window and for displaying message we have used QLabel
.
Share your thoughts in the comments
Please Login to comment...