3

I tried to use observe for my toggleButton

wtarget = widgets.ToggleButtons(
    description='select target',
    options=['A', 'B', 'C', 'D', 'E', 'F'])
wtarget.observe(target_on_value_change, names='value')  

It displayed this error:

AttributeError: 'ToggleButtons' object has no attribute 'observe'

I had no problem with another MacBook but this one showed the problem. I am using MacBook, 10.12. Python Version 4.0.0. ipywidgets was installed via pip.

Thanks.

2 Answers 2

2

This suggests that you have an old version of traitlets. .observe was added in traitlets 4.1:

pip install --upgrade traitlets

You may want to upgrade more than that:

pip install --upgrade ipywidgets
Sign up to request clarification or add additional context in comments.

Comments

0

This error can also arise if you inherit from a widget but forget to call super. That is

from ipywidgets import VBox, Text

class MyToggle(VBox):
    def __init__(self):
        self.children = [Text(description="hello")]

my_toggle = MyToggle()
my_toggle

returns

# ...
# AttributeError: 'MyToggle' object has no attribute '_model_id'

The solution is to call super in __init__:

class MyToggle(VBox):
    def __init__(self):
        super(MyToggle, self).__init__()
        self.children = [Text(description="hello")]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.