A checkbox is supported by PyQt. The widgets name is QCheckBox. If you create a checkbox you can set it to be checked by default using the .toggle() method.

The first parameter after the QCheckBox call is the label text that’s right next to the checkbox. In this article you’ll learn how to place single checkboxes, but you can just as easy create them in a for loop.

Download Examples:
Download PyQt examples

Checkbox

QCheckBox

Import QCheckBox from PyQt5.QtWidgets. Then to create a new checkbox, just call:

cb = QCheckBox('Movie', self)

Where the first parameter is the label next to the checkbox. Then set the position and if you want it checked

cb.move(20, 40)
cb.toggle()

If you want to call a method if the checkbox is called, you can do that like this:

cb.stateChanged.connect(self.someMethod)

pyqt qcheckbox checkbox

Example

The program below creates two check boxes in a window. One of the checkboxes is toggled because the method .toggle() is called.

Complete code:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox

class Example(QMainWindow):

def __init__(self):
super().__init__()

cb = QCheckBox('Movie', self)
cb.move(20, 20)

cb2 = QCheckBox('Music', self)
cb2.move(20, 40)
cb2.toggle()

self.setGeometry(50,50,320,200)
self.setWindowTitle("Checkbox Example")
self.show()

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())