在PyQt5中,每次单击按钮时如何添加复选框?
每次单击按钮时,它都会生成一个复选框。
class Sample extends Component {
state = {
text: sample('igod', 1),
};
componentDidMount() {
setTimeout(() => {
this.setState({
text: this.sample('igod',1)
});
}, 1000);
}
render() {
return (
<div className="text-intro" id="site-type">
{this.state.text}
</div>
);
}
}
我不知道该怎么做!
答案 0 :(得分:1)
尝试一下:
from PyQt5 import QtWidgets, QtGui, QtCore
class Window(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.vlayout = QtWidgets.QVBoxLayout()
self.pushButton_ok = QtWidgets.QPushButton("Press me", self)
self.pushButton_ok.clicked.connect(self.addCheckbox)
self.vlayout.addWidget(self.pushButton_ok)
self.checkBox = QtWidgets.QCheckBox(self)
self.vlayout.addWidget(self.checkBox)
self.setLayout(self.vlayout)
def addCheckbox(self):
#checkBox = QtWidgets.QCheckBox()
self.vlayout.addWidget(QtWidgets.QCheckBox())
application = QtWidgets.QApplication(sys.argv)
window = Window()
window.setWindowTitle('Dynamically adding checkboxes using a push button')
window.resize(250, 180)
window.show()
sys.exit(application.exec_())