python - 使用小部件在 jupyter notebook 中显示 gif
问题描述
如何使用 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
无论我尝试什么都行不通
解决方案
您需要将图像读入文件处理程序并将其读入字节字符串,然后才能将其传递给小部件,如下所示:
# 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'
)
请参阅小部件的文档。Image
推荐阅读
- javascript - 购买活动 GA 网络和应用程序无法正常工作
- parsing - 为解析器/词法分析器规范提供类型系统?
- python - Facebook 图表:帖子未显示给 Facebook 主页粉丝
- flutter - Flutter 中调用 Future 和 Future.microtask 有什么区别?
- php - PHP函数被调用但不带参数
- jira - JQL:当父级移动到“完成”时隐藏“完成”子任务
- javascript - kendoMultiSelect:Java Selenium 如何选择多个值?
- javascript - 如何在 JS 中过滤 JSON 数据
- php - 在查询结果或查询比较中包含列名
- ruby-on-rails-5.2 - 按常用列关联关闭 3 个模型