如何暂停Jupyter笔记本电脑部件,等待用户输入(How to pause Jupyter Not

2019-09-27 13:16发布

在我的笔记本我有一个循环中,我要问用户二进制“是”或“否”。 在此选择的算法是suppposed继续。

for i in range(n_total):
    display.clear_output(wait=True)
    waiting_for_scoring = True
    print("True or False?")
    display.display(widgets.HBox((true_button, false_button)))
    a = true_button.on_click(on_true_button)
    a = false_button.on_click(on_false_button)
    while waiting_for_scoring == True:
        #waiting for user input
        pass

我怎样才能使循环等待,窗口小部件HBox中创建后,并等待用户输入(点击按钮)继续与新的价值回答?

这里是我的按钮有两个功能:

def on_true_button(x):
    global waiting_for_scoring
    print('NO!!!!')
    y_new = 1
    waiting_for_scoring = False
    return y_new

def on_false_button(x):
    global waiting_for_scoring
    print('YES')
    y_new = 0
    waiting_for_scoring = False
    return y_new

你能帮我,直到用户按下按钮停止循环,然后使用该输入? 先感谢您

文章来源: How to pause Jupyter Notebook widgets, waiting for user input