PyQt5 – isChecked() method for Check Box
Last Updated :
22 Apr, 2020
isChecked
method is used to know if the check box is checked or not. This method will return true if the check box is checked else it will return false. If we use this method after creating the check box it will always return False as by default check box is not checked.
Syntax : checkbox.isChecked()
Argument : It takes no argument.
Return : It return bool, true is it checked else false
Below is the implementation.
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__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
self .checkbox = QCheckBox( 'Check box' , self )
self .checkbox.setGeometry( 200 , 150 , 100 , 30 )
self .checkbox.stateChanged.connect( self .method)
check = self .checkbox.isChecked()
print (check)
def method( self ):
print ( self .checkbox.isChecked())
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
False
True
When we run the code False will be printed and after making check box checked it will print True.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...