PyQt5 – Tri-state Check Box
Last Updated :
22 Apr, 2020
When we create a check box, by default there are two state which are either checked i.e True and other is False. But we can add third state to it which is neither True or False with the help of setTristate
method.
Below is how all three states looks like.
Syntax : checkbox.setTristate(True)
Argument : It takes bool as argument.
Action performed : It will add third state to the check box.
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 ):
checkbox = QCheckBox( 'Check Box' , self )
checkbox.setGeometry( 200 , 150 , 100 , 30 )
checkbox.setTristate( True )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...