Lunch Time Python #8: ipywidgets¶

Jupyter Notebooks are a perfect fit for scientific work with Python. They combine the following elements:

  • Code
  • Documentation
  • Visualization
  • UI Controls

This allows us to write scientifically meaningful, executable documents that contain results, their interpretation and their provenance. They are a key element for reproducible research.

What are widgets?¶

Jupyter has a so-called rich display system. If Python code returns an object, Jupyter accesses special methods on the object to decide how to display it. This can involve pretty printing, HTML, images, video, sounds etc:

In [1]:
from PIL import Image
from io import BytesIO
import requests
In [2]:
response = requests.get(
    "https://ssciwr.github.io/lunch-time-python/lunchtime5/thingstaette.png"
)
img = Image.open(BytesIO(response.content))
In [3]:
?img._repr_png_
In [4]:
img
Out[4]: