Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用小部件在jupyter笔记本中显示GIF_Python_Jupyter Notebook_Ipywidgets - Fatal编程技术网

Python 使用小部件在jupyter笔记本中显示GIF

Python 使用小部件在jupyter笔记本中显示GIF,python,jupyter-notebook,ipywidgets,Python,Jupyter Notebook,Ipywidgets,如何使用python小部件在jupyeter笔记本中显示GIF 我试过: gif_box = widgets.Image("sample.gif") 或 但接收器错误: TypeError: __init__() takes 1 positional argument but 2 were given 无论我尝试了什么,它都不会起作用。您需要将图像读入文件处理程序并读入字节字符串,然后才能将其传递到小部件中,如下所示: #以字节形式读取文件并获取文件处理程序。使用“with”确保 #您的文件

如何使用python小部件在jupyeter笔记本中显示GIF

我试过:

gif_box = widgets.Image("sample.gif")

但接收器错误:

TypeError: __init__() takes 1 positional argument but 2 were given

无论我尝试了什么,它都不会起作用。

您需要将图像读入文件处理程序并读入字节字符串,然后才能将其传递到小部件中,如下所示:

#以字节形式读取文件并获取文件处理程序。使用“with”确保
#您的文件在阅读完毕后将被关闭
打开(“sample.gif”、“rb”)作为文件:
#将文件作为字符串读取到'image'中
image=file.read()
widgets.Image(
值=图像,
format='gif'
)
有关
图像
小部件,请参阅

TypeError: __init__() takes 1 positional argument but 2 were given