Добрый день.
Кто-нибудь может накидать простые примеры с checkbox?
#!/usr/bin/env python # -*- coding:utf8 -*- import sys from PyQt4 import QtCore, QtGui class SimpleCheckBox(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.grid = QtGui.QVBoxLayout(self) self.list_check = ['1', '2', '3'] self.checkbox_one = QtGui.QCheckBox(self.list_check[0]) self.checkbox_two = QtGui.QCheckBox(self.list_check[1]) self.checkbox_three = QtGui.QCheckBox(self.list_check[2]) self.label = QtGui.QLabel("Label") self.button = QtGui.QPushButton("Button") self.grid.addWidget(self.checkbox_one, 0) self.grid.addWidget(self.checkbox_two, 1) self.grid.addWidget(self.checkbox_three,2) self.grid.addWidget(self.label, 3) self.grid.addWidget(self.button, 4) self.connect(self.button, QtCore.SIGNAL('clicked()'), self.printer) def printer(self): text = '' if self.checkbox_one.isChecked(): text += self.list_check[0] if self.checkbox_two.isChecked(): text += self.list_check[1] if self.checkbox_three.isChecked(): text += self.list_check[2] self.label.setText(text) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) myapp = SimpleCheckBox() myapp.show() sys.exit(app.exec_())
import sys from PyQt4 import QtGui class Base(QtGui.QWidget): def __init__(self): super(Base, self).__init__() self.startUW() def startUW(self): self.vbox = QtGui.QVBoxLayout() self.checkboxItem() self.vbox.addStretch(1) button = QtGui.QPushButton("Show", self) button.clicked.connect(self.showItem) self.lab = QtGui.QLabel("Ничего не выбрано!", self) self.vbox.addWidget(button, 3) self.vbox.addWidget(self.lab, 4) self.setWindowTitle("Select Item Printer") self.setFixedSize(250, 250) self.setLayout(self.vbox) self.show() def checkboxItem(self): array = ["Пункт 1", "Пункт 2", "Пункт 3"] self.check = [] index = 0 for item_name in array: self.check.append(QtGui.QCheckBox(item_name, self)) self.vbox.addWidget(self.check[index], index) index += 1 def showItem(self): lib = "" index = 0 while index != 3: if self.check[index].isChecked(): lib = lib + " " + self.check[index].text() index += 1 else: index += 1 self.lab.setText(lib) def main(): app = QtGui.QApplication(sys.argv) gui = Base() sys.exit(app.exec_()) if __name__ == "__main__": main()