Reputation: 137
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 error:
TypeError: __init__() takes 1 positional argument but 2 were given
Regardless of what I try it won't work
Upvotes: 2
Views: 1739
Reputation: 2854
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.
Upvotes: 2