PyQt5 – 单选按钮的 setWhatsThis() 帮助文本
在本文中,我们将了解如何设置和访问单选按钮的帮助文本。帮助文本是用于了解未来信息或我们可以获得有关单选按钮的新信息的文本,为了设置帮助文本,我们使用setWhatsThis
方法和访问我们使用whatsThis
方法。
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
下面是实现。
# 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())
输出 :