In this article we will see how we can set and access the help text of the radio button. Help text is the text which is used to know about the future information or what new information we can get about the radio button, in order to set help text we use setWhatsThis
method and for accessing we use whatsThis
method.
For setting help text to radio button –
Syntax : radio_button.setWhatsThis(text)
Argument : It takes string as argument
Return : NoneFor accessing help text of radio button –
Syntax : radio_button.whatsThis()
Argument : It takes no argument
Return : It returns string
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 ): 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( "Radio button" , self ) # setting geometry of radio button self .radio_button.setGeometry( 200 , 150 , 120 , 40 ) # setting help text self .radio_button.setWhatsThis( "To learn more about radio button go to GfG" ) # creating label to show help text label = QLabel( self ) # setting geometry of label label.setGeometry( 200 , 200 , 350 , 30 ) # getting help of text of radio button text = self .radio_button.whatsThis() # showing text in label label.setText(text) # create pyqt5 app App = QApplication(sys.argv) # create the instance of our Window window = Window() # start the app sys.exit(App. exec ()) |
Output :