Skip to content

Button.on_click() handler is called twice for a single click #3996

@decitre

Description

@decitre

Description

Even in a minimal setup, a single click on an ipywidgets.Button causes the registered on_click handler to be called twice.

Reproduce

This occurs using JupyterLab 4.4.5 with ipywidgets 8.1.7 with the code snippet below.

import ipywidgets as widgets

def handler(*args, **kwargs):
    print(f"handler called with: args={args}, kvargs={kwargs}")

button = widgets.Button(description="Click me")
button.on_click(handler)

button

Output when clicking once:

handler called with: args=(Button(description='Click me', style=ButtonStyle()),), kvargs={}
handler called with: args=(Button(description='Click me', style=ButtonStyle()),), kvargs={}

Expected behavior

A single handler call per click

Context

  • ipywidgets version 8.1.7
  • Operating System and version: macOS 14.7.6 (23H626)
  • Browser and version: Firefox 140.0.4 (aarch64)
Troubleshoot Output
python -m jupyter troubleshoot > jupyter-troubleshoot.txt
Command Line Output
python -m jupyterlab --debug > jupyterlab-debug.txt 2>&1
Browser Output
(See attached browser-javascript-console-pasted-content.txt)

If using JupyterLab

  • JupyterLab version: 4.4.5
Installed Labextensions
python -m jupyter labextension list
JupyterLab v4.4.5
/Users/decitre/virtualenv/here-search-demo/share/jupyter/labextensions
        jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
        @jupyter-widgets/jupyterlab-manager v5.0.15 enabled OK (python, jupyterlab_widgets)

jupyter-troubleshoot.txt
browser-javascript-console-pasted-content.txt
jupyterlab-debug.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions