【问题标题】:jupyterlab button event not workingjupyterlab 按钮事件不起作用
【发布时间】:2018-04-25 18:31:26
【问题描述】:

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

有人有解决办法吗?

环境:

  • MacOsX 10 10.12.2
  • Python 2.7.14 :: Anaconda, Inc.
  • Jupyter Notebook 5.4.0
  • Jupyter 实验室 0.31.5

【问题讨论】:

    标签: events jupyter-notebook jupyter-lab


    【解决方案1】:

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

    【讨论】:

    • 嗯,目前最新版本的 Jupyter 即使在普通笔记本上也无法正常工作
    猜你喜欢
    • 1970-01-01
    • 2018-09-18
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2021-08-14
    相关资源
    最近更新 更多