Search code examples
pythonjupyter-notebookipythonipywidgets

ipywidgets clear and reset TextArea


After I add some text to TextArea and run some preprocessing on that text I would like to reset the TextArea widget so I can add new text to it.

For example:

q1 = Textarea(layout=Layout(width='70%', height='100px'))
q1 # opens a window and then I add text to it

enter image description here

q2 = re.sub(r'[^\x00-\x7f]',r'', q1.value)
# do some more preprocessing
q1.reset() # I am looking for something like this

After preprocessing is complete, I'd like to reset q1 to a blank cell so it is ready to take in as input a completely new value.

Any help on this is appreciated.


Solution

  • You can assign any value to the TextArea widget.

    So the answer is really simple.

    q1.value = ""
    
    # Show that the text area is now empty.
    
    q1