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',否則什麼也不知道,在這種情況下,當別名屬性改變時會引發別名屬性事件。 謝謝:) –