import sys,time
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
global t
class category(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Категории')
self.setGeometry(300, 300, 250, 150)
qbtn = QPushButton('Quit', self)
qbtn.resize(qbtn.sizeHint())
qbtn.move(150, 100)
qbtn.clicked.connect(self.close)
self.j = ['bh','ghj','gggggg']
self.z = []
self.vlayout = QtWidgets.QVBoxLayout()
for i in self.j:
self.e = QtWidgets.QCheckBox(i)
self.z.append(self.e)
self.vlayout.addWidget(self.e)
self.setLayout(self.vlayout)
for i in range(len(self.z)):
self.z[i].stateChanged.connect(
lambda state=self.z[i].isChecked(), d = self.j[i] :self.selectBooks(state, d))
def selectBooks(self, toggle, no):
if toggle == QtCore.Qt.Checked:
t.append(no)
else:
t.remove(no)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = category()
w.show()
sys.exit(app.exec_())
собственно сам код