PyQt5 – 单选按钮的描述

PyQt5 – 单选按钮的描述

在这篇文章中,我们将看到如何设置和访问单选按钮的描述。描述基本上是关于单选按钮的详细信息,因为当我们创建GUI(图形用户界面)时,我们会制作很多单选按钮,并且需要对它们进行描述,因为有些单选按钮是用来选择过滤器的,有些是用来选择颜色的,因此需要进行描述。描述将告诉我们关于一个特定的单选按钮的使用和程序,我们需要知道所有的事情。为了访问,我们使用 accessibleDescription 方法,为了设置描述,我们使用 setAccessibleDescription 方法。

对于设置描述 –

语法: radio_button.setAccessibleDescription(info)

参数: 它需要字符串作为参数

返回:

用于访问描述 –

语法: radio_button.accessibleDescription()

参数: 它不需要参数

返回: 它返回字符串。

实现过程:

  1. 创建一个单选按钮

  2. 在setAccessibleDescription方法的帮助下为其设置描述

  3. 创建标签来显示信息

  4. 在accessibleDescription方法的帮助下访问单选按钮的描述,并将其存储在变量中
  5. 在setText方法的帮助下,将该描述设置为标签。
# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
 
 
class Window(QMainWindow):
 
    def __init__(self):
        super().__init__()
 
        # setting title
        self.setWindowTitle("Python ")
 
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
 
        # calling method
        self.UiComponents()
 
        # showing all the widgets
        self.show()
 
    # method for widgets
    def UiComponents(self):
        # creating a radio button
        self.radio_button = QRadioButton(self)
 
        # setting geometry of radio button
        self.radio_button.setGeometry(200, 150, 120, 40)
 
        # setting text to radio button
        self.radio_button.setText("Radio Button")
 
        # setting description to radio button
        self.radio_button.setAccessibleDescription(
            "This is a Geeky button to know if you are geek or not")
 
        # creating label to display button name
        label = QLabel(self)
 
        # setting geometry
        label.setGeometry(100, 200, 400, 30)
 
        # accessing the description
        info = self.radio_button.accessibleDescription()
 
        # showing description in label
        label.setText("Description " + info)
 
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
# start the app
sys.exit(App.exec())

输出:

PyQt5 - 单选按钮的描述

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程