【问题标题】:JupyterLab: How attach an python call back function to a button created using Custom Widget?JupyterLab:如何将 python 回调函数附加到使用自定义小部件创建的按钮上?
【发布时间】:2021-09-28 05:50:30
【问题描述】:

当我使用交互类创建表单时,很容易为点击事件提供python回调函数,如示例My_CallBack_function所示。

from ipywidgets import interactive, widgets

slow = interactive(My_CallBack_function, {'manual': True}, i=widgets.FloatSlider(min=1e4, max=1e6, step=1e4))

如果表单和按钮被创建为自定义小部件,如何运行 python 代码或 python 调用函数'on click'。

【问题讨论】:

    标签: jupyter-notebook jupyter jupyter-lab jupyterhub jupyter-console


    【解决方案1】:
    button0 = wg.Button(description='This is button0', tooltip='This is tooltip')
    output0 = wg.Output()
    display(button0, output0)
    def on_button_clicked0(result):
       with output0:
           print('button0 is clicked')
    button0.on_click(on_button_clicked0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      相关资源
      最近更新 更多