jupyterlab 按钮事件不起作用

jupyterlab button event not working

此代码在 jupyter notebook 中有效,但在 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)

有人有解决办法吗?

环境:

当前,仍然是问题...但是here我找到了解决方案。

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])