Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unobserve doesn't work #3411

Closed
gioxc88 opened this issue Mar 11, 2022 · 2 comments
Closed

Unobserve doesn't work #3411

gioxc88 opened this issue Mar 11, 2022 · 2 comments
Labels
answered The issue has been answered by a community member. closing as answered The issue will be closed as answered soon unless there is further follow-up. pkg:ipywidgets question

Comments

@gioxc88
Copy link

gioxc88 commented Mar 11, 2022

import ipywidgets as w

def test(change):
    print(3)

b = w.Button()
b.on_click(test)

b.unobserve(test)  # does not work
b.unibserve_all()  # does not work

@vidartf
Copy link
Member

vidartf commented Mar 15, 2022

on_click does not use observe, so consequently, unobserve will not do anything in your example. Try setting on_click = None.

@vidartf vidartf added question pkg:ipywidgets answered The issue has been answered by a community member. labels Mar 15, 2022
@jasongrout
Copy link
Member

Please don't set on_click = None. Instead, call the function with the remove=True argument (see docs at https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Events.html?highlight=on_click#Special-events).

b.on_click(test, remove=True)

@github-actions github-actions bot added the closing as answered The issue will be closed as answered soon unless there is further follow-up. label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered The issue has been answered by a community member. closing as answered The issue will be closed as answered soon unless there is further follow-up. pkg:ipywidgets question
Projects
None yet
Development

No branches or pull requests

3 participants