Add code cell from ipywidgets based module

I am trying to create a Python module that depends on ipywidgets library to create widgets in the notebook. In the notebook, I would then import this module and call some functions that would display widgets in the output area of the notebook. Now, I would like to display a button from ipywidgets, click which would add a new code cell in the notebook. I am not able to achieve this functionality in my Python module. I am able to use get_ipython().set_next_input() method in the notebook cell to add a new cell. But I am not able to achieve this when I add this code in another Python module. I found a work around to this here: Creating a new notebook cell from within a widget does not work. · Issue #4983 · ipython/ipython · GitHub but this didn’t work for me.

How do I add a new code cell from a event handler for ipywidget button?