I think what you are describing is very similar to what dpgoldenberg was asking here.
My answer slightly modified from there to do what you want is:
# sort of based on https://github.com/voila-dashboards/voila-material/issues/18
import ipywidgets as widgets
from IPython.display import display
output = widgets.Output()
@output.capture(clear_output=False,wait=True) # based on https://github.com/jupyter-widgets/ipywidgets/issues/1846 and https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html
def sayHello(b):
print("You have pushed the button, congratulations I guess.")
run_button = widgets.Button(
description = 'continue'
)
print("Hello, please push the continue button")
run_button.on_click(sayHello)
display(run_button)
output
And if you don’t need a widget to do this, there other more traditional ways in Jupyter to do something along the lines of what you describe.
For example, see trick #3: ‘Run Demos’ from here.
Or see the image in the GtiHub repository here and note the text, Press Enter to continue...
at the bottom of the image under ‘How to play’. The code for that prompt can be found here. Note the use of input()
. Sadly, the Binder version of that no longer runs (launch link should be this but the image won’t build ), and so I you cannot easily run the simulation to see how the prompts keep allowing you to step forward through things. However, I placed the pertinent code to demonstrate the use of input()
in this gist. You can take the python code from there and place it in a Jupyter cell and start stepping through some of the first steps. It is enough to get a sense of how input()
works before the code errors out.