📜  设置和访问标签的名称——PyQt5

📅  最后修改于: 2022-05-13 01:55:08.297000             🧑  作者: Mango

设置和访问标签的名称——PyQt5

在本文中,我们将了解如何设置和访问标签的描述。
标签是在表单上显示文本的图形控制元素。通常是静态控制;没有交互性。标签通常用于标识附近的文本框或其他小部件。标签的描述是标签的细节,设置描述有助于更好地理解细节以供后端使用。

设置描述 –

要访问描述 -

代码 :

# 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())

输出 :
pyqt-label-description-setAccessibleDescription