Answer the question
In order to leave comments, you need to log in
Why does the program just stop when I try to check a box or click a button?
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_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question