question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropdown ipywidget after unobserve_all() does not accept any further observe()

See original GitHub issue

I use ipywidget 7.0.5 (py35_0) The dropdown ipywidget after unobserve_all() does not work for any further observe(). This is easily reproducible with the following code:

import ipywidgets.widgets as widgets
from IPython.display import display
def helloWorld(_=None):
    print("Hello World!")

# the dropdown is not working properly
widget = widgets.Dropdown( 
            options=[('One', 1), 
                     ('Two', 2),
                     ('Three', 3)],
            description='dropdown_w:',
            value = 2
        )
widget.observe(helloWorld, 'value')
display(widget)
widget.unobserve_all()
widget.observe(helloWorld, 'value')


## instead same code works for other widgets (as it should)
w = widget = widgets.FloatSlider(value = 0.5, min = 0, max = 1, step = 0.1, description = "w")
w.observe(helloWorld, 'value')
display(w)
w.unobserve_all()
w.observe(helloWorld, 'value')

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
NimSedcommented, Jul 14, 2020

Not sure if this is still relevant. But it may help some one. w.unobserve(None,...) does something like what unobserve_all is expected to do. Of course you’d still need to pass names whenever needed. But at least you don’t need to know the exact name of the handler. Specially if you have used a partial when setting the observer.

0reactions
thomasaarholtcommented, Apr 25, 2018

I just ran into this with select as well. Got a minimum working example below for future reference:

import ipywidgets as widgets

def add(value):
    select.options = select.options + (1,) # adds "1" for each event triggered
    select2.unobserve_all() # Three appear
    #select2.unobserve(add) # Five appear
    select2.observe(add)
    
select = widgets.Select(options=('Cheese', 'Onions'), rows=15, value=None)
select2 = widgets.Select(options=('CLICK ME', 'OR ME'), rows=15, value=None)
select2.observe(add)
widgets.HBox([select, select2])
Read more comments on GitHub >

github_iconTop Results From Across the Web

ipywidget observe method called several times for every ...
So the observe method is called 4 times for one single change of the dropdown of the menu. Why is that? secondly this...
Read more >
ipywidgets changelog — Jupyter Widgets 7.6.4 documentation
The main change in this release is that installing ipywidgets 7.6.0 will now automatically enable ipywidgets support in JupyterLab 3.0—a user has no...
Read more >
Ipywidgets with matplotlib - Kapernikov
A simple use case could be adding some basic controls to a plot for interactive data exploration. On the other side of the...
Read more >
ipywidgets Examples of Slider, Dropdown, Checkbox, Text Box
Master the ipywidgets interact function with this tutorial. ipywidgets is a Python library for building interactive HTML widgets for your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found