[英]Displaying gifs in jupyter notebook using widgets
How do you use python widgets to display gifs in a jupyeter notebook.您如何使用 python 小部件在 jupyeter 笔记本中显示 gif。
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不管我怎么尝试都行不通
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'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.