简体   繁体   English

如何嵌套jupyter小部件?

[英]How do you nest jupyter widgets?

I am writing a custom Jupyter widget (made from the cookiecutter ) that would ideally have some custom javascript but then also make use of existing widgets as well. 我写一个自定义的Jupyter小部件 (从制造18.11 ),这将非常有一些自定义JavaScript,但随后又利用现有部件为好。

I can't find documentation on nesting widgets. 我找不到有关嵌套小部件的文档。 How would I make a custom widget that has parts that are custom javascript, as well as using existing widgets? 我如何制作一个包含自定义javascript部分的自定义窗口小部件,以及如何使用现有窗口小部件?

Asked too soon. 问得太早了。 You can use the Box widget (or VBox/HBox). 您可以使用Box小部件(或VBox / HBox)。 See the example code in the doc string. 请参阅doc字符串中的示例代码

Things like, 像,

import ipywidgets as widgets
title_widget = widgets.HTML('<em>Box Example</em>')
slider = widgets.IntSlider()
box1 = widgets.Box([title_widget, slider])
widgets.VBox([box1, box1])

work fine. 工作正常。 And if you look at the code in the class, 如果您查看该类中的代码,

def __init__(self, children=(), **kwargs):
    kwargs['children'] = children
    super(Box, self).__init__(**kwargs)
    self.on_displayed(Box._fire_children_displayed)

def _fire_children_displayed(self):
    for child in self.children:
        child._handle_displayed()

You can see logic for managing children. 您可以看到管理孩子的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM