python-3.x - 如何从多个小部件 ipywidgets 中获取观察值
问题描述
我正在尝试使用来自 ipywidgets 的交互式小部件创建自己的交互式路径选择器,应该有三个选择框,第二个观察第一个的值,第三个观察前一个的选择值,这就是我的问题,我不知道如何添加第三个小部件。
这是我的功能代码:
import os
import getpass
import glob
import ipywidgets as widgets
from ipywidgets import VBox, HBox, Label, interactive, Box
def return_paths(raw_path):
"""Create a list of folders in a given path
skipping those with begin with '.' and are empty
"""
paths = [folder for folder in os.listdir(raw_path)
if os.path.isdir(os.path.join(raw_path, folder)) and not folder.startswith('.')
and len(os.listdir(os.path.join(raw_path, folder))) != 0
]
paths.sort()
return paths
def get_select2(*args):
options = return_paths(os.path.join(raw_path, select_1.value))
select_2.options = options
def process(Feature,ID):
print(Feature,ID)
def run():
w = interactive(process, Feature=select_1, ID=select_2)
display(HBox([Label('Select the folder you want process:'), w.children[0], w.children[1]]))
display(w.children[2])
user = getpass.getuser()
raw_path = f'/home/{user}/downloads/0_raw/'
raw_folders = []
select_1 = widgets.Select(
options=return_paths(raw_path),
)
select_2 = widgets.Select()
select_3 = widgets.Select()
select_1.observe(get_select2)
run()
此刻正在使用两个选定的框,如何添加第三个?任何想法?
解决方案
推荐阅读
- concurrency - DDD - 并发和命令重试有副作用
- asp.net - 下拉菜单的 ASP:NET web api 问题
- node.js - 指示在 NodeJS 中通过 Twilio API 接收到 WhatsApp 消息?
- amazon-redshift - Redshift to_date 问题:日期格式无效;指定日期两次
- docusignapi - 只能从一个文件夹中检索 20 个文档
- php - 使用php从json中的嵌套数组中获取数据
- typescript - 打字稿在linux获取模块未找到错误中表现不同
- core-data - 线程 1:“NSFetchedResultsController 的一个实例需要一个带有排序描述符的获取请求”
- terraform - Terraform 中动态入口中的 Rule_nos
- python - 网页抓取到 html 中的特定点然后停止