Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm building an application in which a check box is connected to a button and the button only gets activated when the check box is marked. I have the button and check box defined in initUI function and i have created a button hide function which ive connected to my check box, but i keep getting an error that 'qbtn'(my button) is not defined. What should i do?

initUI:
Python
def initUI(self):   
                       
         # Add push button       
        qbtn = QtGui.QPushButton('Quit', self)
        #connect to button press
        qbtn.clicked.connect(self.ButtonPress)
        qbtn.resize(qbtn.sizeHint())
         
        qbtn.move(50, 50)
        #Add Check Box
        cb = QtGui.QCheckBox('Agree', self)
        cb.move(20, 20)
        cb.toggle()
        cb.stateChanged.connect(self.ButtonHide)   



ButtonHide:
Python
def ButtonHide(self, state):
                       
            if state == QtCore.Qt.Checked:
                qbtn.setEnabled(True) 
            else:
                qbtn.setEnabled(False) 



Error Message:
VB
File "<wingdb_compile>", line 46, in ButtonHide
NameError: global name 'qbtn' is not defined
Traceback (most recent call last):


Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900