jupyterlab按钮事件无法正常工作

时间:2018-04-25 18:31:27

标签: events jupyter-notebook jupyter-lab

此代码在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)

有没有人有解决方案?

ENV:

  • MacOsX 10 10.12.2
  • Python 2.7.14 :: Anaconda,Inc。
  • Jupyter Notebook 5.4.0
  • Jupyter Lab 0.31.5

1 个答案:

答案 0 :(得分:3)

当前,仍然知道问题......但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])