Open In App

PyQt5 – setWhatsThis() help text of Radio button

Last Updated : 22 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 : None

For 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 :



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads