如何使用 python 小部件在 jupyeter 笔记本中显示 gif。
我已经尝试过:
gif_box = widgets.Image("sample.gif")
或
gif_box = widgets.Video("sample.gif")
但接收器错误:
TypeError: __init__() takes 1 positional argument but 2 were given
无论我怎么尝试,都行不通
最佳答案
您需要将图像读入文件处理程序并将其读入字节字符串,然后才能将其传递到小部件中,如下所示:
# 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
小部件。
关于python - 使用小部件在 jupyter 笔记本中显示 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60640375/