如何在Pyqt4中将我的复选框连接到按钮? [英] How Do I Connect My Check Box To Button In Pyqt4?

查看:88
本文介绍了如何在Pyqt4中将我的复选框连接到按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,其中一个复选框连接到一个按钮,只有当复选框被标记时才会激活该按钮。我有在initUI函数中定义的按钮和复选框,我已经创建了一个按钮隐藏功能,它已连接到我的复选框,但我不断收到错误'qbtn'(我的按钮)未定义。我该怎么办?



initUI:

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:

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:




ButtonHide:

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







错误信息:




Error Message:

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





谢谢!



Thanks!

推荐答案

这篇关于如何在Pyqt4中将我的复选框连接到按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆