How to create buttons in Jupyter

Interact with your functions by clicking buttons in your notebook

Diego Penilla
9 min readFeb 25, 2019
Photo by Owen Beard on Unsplash

I really like Jupyter Notebooks. Whenever I’m using one, I have the feeling of it being basically an interactive spell book: able to display text, images, videos, including math formulas and code, and create an inner environment with your variables and functions. Compared to carving stones with your notes, this tool makes you feel like you are in the future.

And there is still an interesting aspect of notebooks that I haven’t mentioned: you can also actively interact with your notebook by directly manipulating widgets and allowing specific type of user-computer interactions. Let’s see how we can do this using ipywidgets, a very cool package with all the tools you need to build a simple GUI.

Installation

Let’s start by installing and enabling the package executing the following code in your terminal.

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

--

--