当ipywidgets按下按钮时如何恢复功能

时间:2018-05-25 02:26:27

标签: python python-3.x ipywidgets

我试着做下一个例子。我的问题是,当我按下一个按钮时,我需要回到功能"索引"所以我可以继续我正在做的事情(在下一行,我不想再次开始),并输入以下条件之一:如果continue.on_click(点击)。我怎么能在按下按钮后回到我离开的地方?

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

感谢。

0 个答案:

没有答案