【发布时间】:2018-10-26 20:01:29
【问题描述】:
试图重现http://traitlets.readthedocs.io/en/stable/using_traitlets.html#observe 中的示例,但使用小部件作为类属性,行为会发生变化,并且不会观察到变化
from ipywidgets import Label
from traitlets import HasTraits, Unicode, observe
class Foo(HasTraits):
bar = Label()
baz = Unicode()
@observe('bar')
def _observe_bar(self, change):
print(change['old'])
print(change['new'])
f = Foo()
f.bar = Label('hello') # No printing
【问题讨论】:
标签: python ipython jupyter-notebook observer-pattern ipywidgets