Friday, October 10, 2025
HomeLanguagesSetting and accessing name of a Label – PyQt5

Setting and accessing name of a Label – PyQt5

In this article we will see how we can set and access the description of the label. A label is a graphical control element which displays text on a form. It is usually a static control; having no interactivity. A label is generally used to identify a nearby text box or other widget. Description of label is the details of the label, setting description helps in better understanding of the details for back-end purposes. To set the Description – 

Syntax : label.setAccessibleDescription(details) Argument : It takes string as argument. Return : No return value.

To access the Description –

Syntax : label.setaccessibleDescription() Argument : It takes no argument. Return : It returns string.

Code : 

Python3




# importing the required libraries
 
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from PyQt5 import QtGui
import sys
 
 
 
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
 
        # set the title
        self.setWindowTitle("Description")
 
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
 
        # creating a label widget
        self.label_1 = QLabel("Label", self)
 
        # moving position
        self.label_1.move(100, 100)
 
        # setting up border
        self.label_1.setStyleSheet("border: 1px solid black;")
 
        # setting up the description of label_1
        self.label_1.setAccessibleDescription(
                      "This is description of label")
 
        # getting description of label_1
        info = self.label_1.accessibleDescription()
 
        # new label to display info
        self.label_2 = QLabel(info, self)
        self.label_2.move(100, 130)
        self.label_2.adjustSize()
 
        # show all the widgets
        self.show()
 
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
# start the app
sys.exit(App.exec())


Output : pyqt-label-decription-setAccessibleDescription

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS