python – How to insert text at caret for ipywidgets textarea

I am using ipywidgets in a jupyter notebook and am trying to insert text into a Text box. I have code that will append the appropriate text to the end, but I would like it to insert at the current text cursor instead. Here is a mock up of what a currently have:

from ipywidgets import Button,Text

a = Text(description='text',
b = Button(description='Awesome',

def on_button_clicked(b):



When I tried to google my question, I found lots of examples for doing this with javascript or tk, but I can’t seem to figure out how to do this with ipywidgets.

How do I get the caret position of the ipywidgets Text box?