【问题标题】:Displaying gifs in jupyter notebook using widgets使用小部件在 jupyter notebook 中显示 gif
【发布时间】:2020-06-23 16:38:40
【问题描述】:
如何使用 python 小部件在 jupyeter notebook 中显示 gif。
我试过了:
gif_box = widgets.Image("sample.gif")
或
gif_box = widgets.Video("sample.gif")
但接收器错误:
TypeError: __init__() takes 1 positional argument but 2 were given
不管我怎么尝试都行不通
【问题讨论】:
标签:
python
jupyter-notebook
ipywidgets
【解决方案1】:
您需要将图像读入文件处理程序并将其读入字节字符串,然后才能将其传递给小部件,如下所示:
# 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'
)
查看docs 以获取Image 小部件。