【发布时间】:2020-05-03 23:36:38
【问题描述】:
我有 2 个复选框,我需要它们按如下方式工作:
如果第一个未被选中(启用项目参与者)并且第二个已被选中(仅允许使用..),它也将被取消选中。但是当我检查第一个时,第二个将保持未选中状态。 Alogn 有一个布尔变量only_def_actors,如果第二个复选框未选中,则需要将其设置为False。
我已经尝试过了,但是我得到了 `TypeError: 'bool' object is not callable。我不知道应该更改哪个属性才能使其正常工作。或者可能更容易做到?
在 main.kv 中:
#defined id of checkbox to use in .py
only_def_act: only_def_actors
Label:
text: "Enable project actors"
CheckBox:
on_active: root.actors_checkbox_click(self, self.active)
active: True
Label:
text: "Allow using only defined actors"
CheckBox:
id: only_def_actors
on_active: root.only_def_actors_checkbox_click(self, self.active)
在 main.py 中:
#defined variables
only_def_act = ObjectProperty(None)
actors_status = BooleanProperty(True) #this one is set to be checked by default
only_def_actors = BooleanProperty(False) #this one is set to be unchecked by default
# Callback for the checkbox
def only_def_actors_checkbox_click(self, instance, value):
if value is True:
self.only_def_actors = True
print("T")
else:
self.only_def_actors = False
self.only_def_act.active(False)
print("F")
# Callback for the checkbox
def actors_checkbox_click(self, instance, value):
if value is True:
self.actors_status = True
print("T")
else:
self.actors_status = False
self.only_def_actors_checkbox_click(instance, False)
print("F")
【问题讨论】: