How to pause Jupyter Notebook widgets, waiting for user input

橙三吉。 提交于 2019-12-24 07:06:29

问题


In my notebook I've a loop in which I want to ask the user to binary "Yes" or "No". On this choice the algorithm is suppposed to continue.

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

How can I make the loop to wait, after the widgets HBox creation, and wait for user input (button click) to continue with the new value answered?

Here's my two functions for the buttons:

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

Could you help me to stop the loop until the user presses the button and then use this input? Thank you in advance

来源:https://stackoverflow.com/questions/54629964/how-to-pause-jupyter-notebook-widgets-waiting-for-user-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!