0
这里是我的简化代码:当我绑定到AliasProperty时会发生什么?
class Player(Widget):
_health = NumericProperty(100)
def _get_health(self):
return self._health
health = AliasProperty(_get_health, bind=['_health'])
我这样做是为了使health
'只读'。
奇怪的是,当我删除bind=['_health']
时,它不起作用。
所以我的问题是:bind=['_health']
实际上做了什么?我知道AliasProperty
允许我定义一个getter和可选setter,它在该属性被访问时运行(类似于Python的@property
)。
那么在这种情况下,为什么bind=['_health']
,以及为什么该属性不起作用(不反映底层_health
的状态)?
我明白了。当'right''改变'时,除非我们明确指定我们依赖于'x'和'width',否则什么也不知道,在这种情况下,当别名属性改变时会引发别名属性事件。 谢谢:) –