首页 > 解决方案 > 当ipywidgets按钮按下时如何恢复功能

问题描述

我试图做下一个例子。我的问题是,当我按下一个按钮时,我需要返回到“索引”功能,这样我才能继续我正在做的事情(在下一行,我不想重新开始),然后输入其中一个条件:如果 continue.on_click(clicked)。按下按钮后如何回到我离开的地方?

import IPython.display 
import ipywidgets
import ipywidgets as widgets

def clicked(option):
    if option.description == "continue":
        print ('continue')
        return ('continue')
    elif option.description == "finish":
        print('finishhh')
        return ('finishhh')

def index():
    print ('hello')
    continues = ipywidgets.Button()
    finish = ipywidgets.Button()

    continues.description =  "continue"
    finish.description =  "finish"

    display(continues, finish)
    continues.on_click(clicked)
    finish.on_click(clicked)
    if continues.on_click(clicked) == "continue":
        print('here!')
    elif finish.on_click(clicked) == "finish":
        print('here2')

index()

谢谢。

标签: pythonpython-3.xipywidgets

解决方案


推荐阅读