I created a DropDown widget:
self.foo_widget = widgets.Dropdown(description='Lorem ipsum', width=100) self.foo_widget.options = ['Default', 'A', 'B', 'C', 'D']
And I am capturing the on_trait_change event:
self.foo_widget.on_trait_change(self.handler, 'value')
Now in the handler handler function, I want to return the value of DropDown to 'Default' . But the following code changes the value without updating the display of the widget. DropDown still shows the original selection value (for example, "C"), although print self.foo_widget.value shows the default value.
self.foo_widget.value = 'Default'
Is this an IPython Widget Error? What is the correct way to trigger a view update?
In fact, for list widgets, it seems that I need to clear the parameters and reassign the parameters to make the widget display refresh. Does anyone have a similar experience?
Update: nluigi's answer below works fine. As shown in the following example.
class test(object): def __init__(self): self.foo_widget = widgets.Dropdown(description='Lorem ipsum', width=100) self.foo_widget.options = ['Default', 'A', 'B', 'C', 'D'] self.foo_widget.on_trait_change(self.handler, 'value') display(self.foo_widget) def handler(self, name, old, new): print(self.foo_widget.value) print(self.foo_widget.selected_label) self.foo_widget.value = 'Default' self.foo_widget.selected_label = 'Default'
python user-interface ipython-notebook
Pan yan
source share