Check out Kite (free AI Coding Assistant) → Link



Buy Me a Coffee? Your support is much appreciated!

PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn

Source Code:   

import sys
from data import d
from PyQt5.QtWidgets import QApplication, QWidget, QCheckBox, QGroupBox, QGridLayout, QVBoxLayout


class AppDemo(QWidget):
    def __init__(self):
        super().__init__()

        lst = d

        layout = QVBoxLayout()

        self.groupBoxLayout = QGridLayout()
        self.groupBox = QGroupBox('Checkboxes')
        self.groupBox.setFlat(False)
        self.groupBox.setLayout(self.groupBoxLayout)
        layout.addWidget(self.groupBox)

        for indx, value in enumerate(lst):
            # print('Row {0}'.format(indx // 3))
            # print('Column {0}'.format(indx % 3))
            # print(value)

            self.check_box = QCheckBox(value)
            self.check_box.setStyleSheet('font-size: 25px;')
            self.check_box.clicked.connect(self.toggle_checkbox)
            self.groupBoxLayout.addWidget(self.check_box, indx // 4, indx % 4)

        self.setLayout(layout)

    def toggle_checkbox(self):
        sender = self.sender()
        if isinstance(sender, QCheckBox):
            print('{0} value is {1}'.format(sender.text(), sender.isChecked()))


if __name__ == '__main__':
    app = QApplication(sys.argv)

    demo = AppDemo()
    demo.show()

    try:
        sys.exit(app.exec_())
    except SystemExit:
        print('Closing Window...')