Displaying Gifs In Jupyter Notebook Using Widgets
How do you use python widgets to display gifs in a jupyeter notebook. I have tried: gif_box = widgets.Image('sample.gif') or gif_box = widgets.Video('sample.gif') but receiver
Solution 1:
You need to read your image into a file handler and read it into a byte string before you can pass it into the widget like so:
# read file as bytes and get file handler. use `with` to ensure
# your file is closed after you're done reading it
with open("sample.gif", "rb") as file:
# read file as string into `image`
image = file.read()
widgets.Image(
value=image,
format='gif'
)
See the docs for the Image
widget.
Post a Comment for "Displaying Gifs In Jupyter Notebook Using Widgets"