import PyQt5.QtWidgets as qtw app = qtw.QApplication([]) checkbox = qtw.QCheckBox('Check me') checkbox.setChecked(True) checkbox.stateChanged.connect(lambda state: print(f'Checkbox state: {state}')) checkbox.show() app.exec()
import PyQt5.QtWidgets as qtw app = qtw.QApplication([]) checkbox = qtw.QCheckBox('Check me') checkbox.setChecked(False) if checkbox.isChecked(): print('The checkbox is checked') else: print('The checkbox is not checked') checkbox.show() app.exec()This example demonstrates how to check whether a QCheckBox is currently checked or unchecked. In this example, the checkbox is initially unchecked, and the code checks its state and prints a message accordingly. Overall, the PyQt5 QtGui QCheckBox is a useful component for creating graphical user interfaces that include options for the user to select or deselect. It can be used in a variety of Python applications that require user input.