Skip to content
Related Articles

Related Articles

Improve Article

PyQt5 – Description of Radio Button

  • Last Updated : 22 Apr, 2020

In this article we will see how we can set and access the description of the radio button. Description is basically a detailed information about the radio buttons because when we create GUI (Graphical User Interface) we make lot of radio button and there is a need describe them as some radio button will be for choosing filter some will be for selecting color etc therefore need of description is required. Description will tell the use and procedure all things we need to know about a particular radio button.

In order to access the we use accessibleDescription method and in order to set the description we use setAccessibleDescription method.

For setting description –
Syntax : radio_button.setAccessibleDescription(info)
Argument : It takes string as argument
Return : None

For accessing description –
Syntax : radio_button.accessibleDescription()
Argument : It takes no argument
Return : It return string

Implementation procedure :
1. Create a radio button
2. Set description to it with the help of setAccessibleDescription method
3. Create label to display the information
4. Access the description of radio button with the help of accessibleDescription method and store it in variable
5. Set this description to label with the help of setText method

Below is the implementation –

# 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):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # calling method
        # showing all the widgets
    # 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
            "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

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :