PyQt5 – How to change color of the label ?

While creating a Label in PyQt5, we can see that there is no background color. In this article we will see how to add background color to the Label.

In order to add border to the Label we will use label.setStyleSheet() method, this will add the background color to the label, it is same like designing the CSS style sheet.

Syntax : label.setStyleSheet(“background-color: cyan”)

Argument : It takes string as argument.

Action performed: It changes the background color of the label.

Code :





# 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('Light green', self)
        # moving position
        self.label_1.move(100, 100)
        # setting up background color
        self.label_1.setStyleSheet("background-color: lightgreen")
        # creating a label widget
        # by default label will display at top left corner
        self.label_2 = QLabel('Yellow', self)
        # moving position
        self.label_2.move(100, 150)
        # setting up background color and border
        self.label_2.setStyleSheet("background-color: yellow; 
                                    border: 1px solid black;")
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app


Output :

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.