【问题标题】: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 小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 2019-05-02
      • 2020-12-12
      • 2019-01-28
      相关资源
      最近更新 更多