Using Python 3.7 in a Jupyter notebook, the code below shows a text entry field that triggers the handle_submit function to print out some output. In this example 40 repetitions of the input.
from ipywidgets import widgets
from IPython.display import display
text = widgets.Text()
display(text)
def handle_submit(sender):
print('\n'.join([text.value] * 40 ))
text.on_submit(handle_submit)
Running this code displays a text box.
If you enter text in the box and press Enter, the handle_submit function is run and the "result" is printed.
This can be used multiple times, but all old output is kept. So after using the entry field a couple of times you need to scroll endlessly to get to the new result.
Is there a command to clear the cell output before printing new output from the handle_submit function? Unlike this example, the output length is not fixed, so the solution should handle differently sized outputs.