如何在猕猴桃中回呼复选框?

时间:2020-07-31 14:17:16

标签: python function checkbox radio-button kivy

    self.t_and_c = Label(text='Accept terms and conditions: ')
    self.inside.add_widget(self.t_and_c)
   
    self.checkbox_first = CheckBox(active=False)
    self.checkbox_first.bind(active = self.checkbox_status)
    self.inside.add_widget(self.checkbox_first)
    
    self.pvt_policy = Label(text='Accept private policy: ')
    self.inside.add_widget(self.pvt_policy)
    
    self.checkbox_second = CheckBox(active=False)
    self.checkbox_second.bind(active = self.checkbox_status)
    
    self.inside.add_widget(self.checkbox_second)
    self.inside.add_widget(Label())
    self.enter = Button(text='Enter information', disabled=True)
    self.inside.add_widget(self.enter)
    
    
def checkbox_status(self, instance):
    if self.checkbox_first.active == True and self.checkbox_second.active == True:
        self.enter.disabled == False
    else:
        self.enter.disabled == True

我想创建一个禁用按钮的功能,直到两个“复选框”被选中为止。我正在尝试调用此复选框,但出现此错误:

TypeError: checkbox_status() takes 2 positional arguments but 3 were given

对于为什么我需要另一个输入参数感到困惑,不胜感激,但是请以Python语言而不是kv给出答案吗?

1 个答案:

答案 0 :(得分:0)

用于绑定到active的{​​{1}}属性的回调期望使用两个参数,即Checkbox实例和CheckBox属性的新值来调用该回调。 。由于您使用的是active方法,

checkbox_status()

是类的实例方法(请注意self.checkbox_second.bind(active = self.checkbox_status) ),self.参数将自动插入为方法调用的第一个参数。这将导致self方法的参数列表为:

checkbox_status()

因此,方法的签名应为:

checkbox_status(self, checkbox_instance, new_value)

def checkbox_status(self, instance, new_value):