Ipywidget选择框不打开

1 投票
1 回答
17 浏览
提问于 2025-04-14 18:34

我有一个Jupyter笔记本,并且正在使用leafmap。我想添加一个文件选择器,这样可以打开一个小工具来选择本地文件。我在一个单元格里写了以下代码:

import ipywidgets as widgets
from ipyfilechooser import FileChooser
import os

padding = "0px 0px 0px 5px"
style = {"description_width": "initial"}

tool_output = widgets.Output(
    layout=widgets.Layout(max_height="150px", max_width="500px", overflow="auto")
)

file_type = widgets.ToggleButtons(
    options=["GeoTIFF", "COG", "STAC", "Microsoft"],
    tooltips=[
        "Open a local GeoTIFF file",
        "Open a remote COG file",
        "Open a remote STAC item",
        "Create COG from Microsoft Planetary Computer",
    ],
)
file_type.style.button_width = "110px"

file_chooser = FileChooser(
    os.getcwd(), sandbox_path=m.sandbox_path, layout=widgets.Layout(width="454px")
)
file_chooser.filter_pattern = ["*.tif", "*.tiff"]
file_chooser.use_dir_icons = True

source_widget = widgets.VBox([file_chooser])

但是当我运行这个单元格时,没有出现选择框。我哪里出错了呢?

1 个回答

1

在单元格的最后加上 display(source_widget) 这行代码。

在这里输入图片描述

撰写回答