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 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 : NoneFor 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 –
Python3
# 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 ()) |
Output :