问题
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