小编Sta*_*ych的帖子

如何将小部件添加到 ipython/jupyter 中的容器小部件

我正在尝试制作 VBox 小部件,并在单击按钮时添加一个带有文本的新行。

我尝试以下代码

import ipywidgets as wg
from ipywidgets import Layout
from IPython.display import display

vb = wg.VBox([wg.Text('1'),wg.Text('2')])
btn = wg.Button(description = 'Add') 

def on_bttn_clicked(b):        
    vb.children=tuple(list(vb.children).append(wg.Text('3'))) 

btn.on_click(on_bttn_clicked)
display(vb, btn)

list(hb.children)
Run Code Online (Sandbox Code Playgroud)

但是分配“hb.children =”不起作用......有没有办法在同一单元格中使用代码编辑容器小部件?

python-3.x jupyter-notebook ipywidgets

3
推荐指数
1
解决办法
2678
查看次数

标签 统计

ipywidgets ×1

jupyter-notebook ×1

python-3.x ×1