Python3 PyQt4 Creating a simple QCheckBox and changing a Boolean variable

前端 未结 2 1780
生来不讨喜
生来不讨喜 2021-01-15 00:54

So I have been trying to write a GUI using Python 3.3 and PyQt4. I have been through a few tutorials and I still can\'t figure out how to have a Checkbox checking and unchec

2条回答
  •  长情又很酷
    2021-01-15 01:37

    Try to avoid using a global variables.

    Instead, make the checkbox an attribute of the window and test its state directly:

    class SelectionWindow(QtGui.QWidget):
        def __init__(self, parent=None):
            super(SelectionWindow, self).__init__(parent)
            self.ILCheckbox = QtGui.QCheckBox(self)
            self.ILCheckbox.setChecked(QtCore.Qt.Unchecked)
            MainLayout = QtGui.QGridLayout()
            MainLayout.addWidget(self.ILCheckbox, 0, 0, 1, 1)
            self.setLayout(MainLayout)
    ...
    
    window = SelectionWindow()
    print window.ILCheckbox.isChecked()
    

提交回复
热议问题