Skip to content

Creating of buttons in callback doesn't work #18

@tobyX

Description

@tobyX

I want to create buttons after somebody did some input and clicked a button. This is working fine in default voila but not with voila-material.

I installed the latest version via pip: 0.3.0

Example:

import ipywidgets.widgets as widgets
import IPython.display as display

create_button = widgets.Button(description="create button")
box = widgets.Box()
output = widgets.Output()

def print_description(btn):
    with output:
        display.clear_output()
        print(f"Button {btn.description} is clicked")

def callback_on_create(btn):
    try:
        box.children = ()
        for i in range(0, 3):
            nb = widgets.Button(description=f"new button {i}")
            nb.on_click(print_description)
            box.children += (nb,)
    except:
        pass

create_button.on_click(callback_on_create)

display.display(
    widgets.VBox([
        widgets.HBox([create_button]),
        box,
        output
    ])
)

A click on the create button will create following error multiple times:

11:38:10.803 Exception opening new comm default.js:969
    _handleCommOpen default.js:969
11:38:10.805 Error: "Object 'jupyter.widget' not found in registry"
    loadObject default.js:1494
    loadObject default.js:1473
    _handleCommOpen default.js:962
    _handleMessage default.js:1068
    _msgChain default.js:122
default.js:127
    _msgChain default.js:127

The buttons are created and shown but the second callback doesn't work.

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