PyQt5 – How to add border on QLabel ?

When we create Label in PyQt5, we can see that there are no borders like there exist in Push Buttons, in this article we will see how to add border to the Label.

In order to add border to the Label we will use label.setStyleSheet() method, this will add the border to the label, also we can set the thickness as well as color of the border.

Syntax : label.setStyleSheet(“border: 1px solid black;”)

Argument : It takes string as a argument.

Action performed : This will create a border on label with thickness of 1px and color will be black.

Below is the Python implementation –





# importing the required libraries
from PyQt5.QtWidgets import * 
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
        # by default label will display at top left corner
        self.label_1 = QLabel('It is Label 1', self)
        # moving position
        self.label_1.move(100, 100)
        # setting up border
        self.label_1.setStyleSheet("border: 1px solid black;")
        # creating a label widget
        # by default label will display at top left corner
        self.label_2 = QLabel('It is Label 2', self)
        # moving position
        self.label_2.move(100, 200)
        # setting up border
        self.label_2.setStyleSheet("border: 3px solid blue;")
        # 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 :

Be the First to upvote.

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