4givN
4givN

Reputation: 3234

jupyterlab button event not working

This code work in jupyter notebook, but doesn't work in jupyterlab:

import ipywidgets as widgets
from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)

def on_button_clicked(b):
    print("Button clicked.")

button.on_click(on_button_clicked)

Does anyone have a solution ?

Env:

Upvotes: 3

Views: 4836

Answers (1)

4givN
4givN

Reputation: 3234

Current, still know as issue ... but here I found a solution.

import ipywidgets as widgets
button = widgets.Button(description='Display Chart')
out = widgets.Output()
def on_button_clicked(b):
    button.description = 'clicked'
    with out:
        print('Ay')

button.on_click(on_button_clicked)
widgets.VBox([button, out])

Upvotes: 8

Related Questions