Jupyter笔记本下载按钮

时间:2019-07-01 23:26:17

标签: python jupyter-notebook ipython ipywidgets

我正在尝试在jupyter笔记本(IPython)中实现下载按钮。我知道按钮小部件确实存在于jupyter中,如下所示。

from ipywidgets import Button

...

btn_download = widgets.Button(
    description='Download',
    button_style='', # 'success', 'info', 'warning', 'danger' or ''
    tooltip='Download',
    icon='download',
    layout=button_layout )

# Then implement download in on_click 
def on_button_download_clicked(b):
    # Handle download using urlopen
    filedata = urllib.request.urlopen(r'file://' + filepath)
    datatowrite = filedata.read()
    with open("download.fid", 'wb') as f:  
        f.write(datatowrite)

# Register callback
btn_download.on_click(on_button_download_clicked)

但是,这似乎不起作用。我尝试了其他几种方法,例如使用urlretrieve,但仍然无法正常工作。

我也知道存在诸如使用ipython.display.FileLink之类的解决方案,但是我想以按钮的形式来解决它。

这有什么解决方法吗?

0 个答案:

没有答案
相关问题