PyQt5 – How to align Text of Label

In this article, we will see how we can align text of labels in PyQt5 application, we can align text in three different ways which are left, right and Center.

Syntax :


In order to use use this we have to import Qtcore from PyQt5

from PyQt5 import QtCore

Below is the implementation :





# importing the required libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore
from PyQt5.QtGui import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
        # creating a label widget
        self.label_1 = QLabel('Left', self)
        # moving position
        self.label_1.move(100, 100)
        # setting up border
        self.label_1.setStyleSheet("border: 1px solid black;")
        # setting alignment to left
        # creating a label widget
        self.label_2 = QLabel('Centre', self)
        # moving position
        self.label_2.move(100, 130)
        # setting up border
        self.label_2.setStyleSheet("border: 1px solid black;")
        # setting alignment to centre
        # creating a label widget
        self.label_3 = QLabel('Right', self)
        # moving position
        self.label_3.move(100, 160)
        # setting up border
        self.label_3.setStyleSheet("border: 1px solid black;")
        # setting alignment to right
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :


Please write to us at to report any issue with the above content.