Open In App

PyQt5 - How to stop radio button from getting checked

Last Updated : 22 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
In this article we will see how to stop the radio button for getting checked, some times there is a need of blocking a radio button so that user can't check it. In order to stop the radio button from getting checked we have to change the check-able property of radio button and set it to False.
Syntax : radio_button.setCheckable(False) Argument : It takes bool as argument Action : It will not allow button to get checked.
Below is the implementation. Python3 1==
# 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")

        # changing check-able property of radio button
        self.radio_button.setCheckable(False)


# create pyqt5 app
App = QApplication(sys.argv)

# create the instance of our Window
window = Window()

# start the app
sys.exit(App.exec())
Output :

Next Article
Article Tags :
Practice Tags :

Similar Reads