python - 使用 kivy 使用另一个复选框选中或取消选中复选框
问题描述
我有 2 个复选框,我需要它们按如下方式工作:
如果第一个未被选中(启用项目参与者)并且第二个已被选中(仅允许使用..),它也将被取消选中。但是当我检查第一个时,第二个将保持未选中状态。如果未选中第二个复选框,则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")
解决方案
您从这一行得到错误:
self.only_def_act.active(False)
它试图调用CheckBox
active
属性(它是 a BooleanProperty
),就好像它是一个方法一样。
也许你的意思是:
self.only_def_act.active = False
推荐阅读
- javascript - 如何在 Angular 中获取一条路径
- excel - 如何使用 Application.WorksheetFunction.Match 捕获错误并进行处理?
- ios - 如何在 Xcode 中增加范围标题和搜索栏的字体大小?
- javascript - Getting GitHub's text styling
- node.js - testcafe 正在打开浏览器并默认为 /browser/connect/.... 并且无法执行测试
- swift - 如何处理 serviceSubscriberCellularProviders 以仅从物理 SIM 卡而不是 eSIM 获取数据?
- html - overlap div elements with box-shadow property
- database - Cloud Foundry 中的数据库实例是什么?
- aliexpress - 是否有将产品添加到速卖通订单列表的 API
- svn - SVN状态,忽略道具?