Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jupyter notebook 为多个IPyWidget创建观察处理程序_Jupyter Notebook_Ipywidgets_Voila - Fatal编程技术网

Jupyter notebook 为多个IPyWidget创建观察处理程序

Jupyter notebook 为多个IPyWidget创建观察处理程序,jupyter-notebook,ipywidgets,voila,Jupyter Notebook,Ipywidgets,Voila,我必须根据单词列表动态创建按钮集合。 我用一个类创建它们。 然后,我必须动态地查看用户单击了多少按钮,并相应地采取行动(获取每列单击按钮的集合) 我的问题是如何处理事件处理程序。 我无法决定如何集体处理创建的所有按钮。我基本上需要一个监听器,每次发生变化时,都会看到有多少按钮被点击,当然,点击并松开相应的按钮 到目前为止,这是我的代码: class verticalButtons(): def __init__(self,concepts): self.verticalbuttons

我必须根据单词列表动态创建按钮集合。 我用一个类创建它们。 然后,我必须动态地查看用户单击了多少按钮,并相应地采取行动(获取每列单击按钮的集合)

我的问题是如何处理事件处理程序。 我无法决定如何集体处理创建的所有按钮。我基本上需要一个监听器,每次发生变化时,都会看到有多少按钮被点击,当然,点击并松开相应的按钮

到目前为止,这是我的代码:

class verticalButtons():

def __init__(self,concepts):
    self.verticalbuttons = self.create_buttons(concepts)

def create_buttons(self,concepts):
    import ipywidgets
    wd_buttons = []
    for i,concept in enumerate(concepts):
        newbutton = ipywidgets.Button(description=concept,
                                     button_style='success')
        wd_buttons.append(newbutton)

    verticalbox = VBox(wd_buttons)
    return verticalbox
基本上,将单词列表传递给类会创建一个带有按钮的VBox

mylist1 = ['1first','1second','1third']
mylist2 = ['2first','2second','2third','2fourth']
one = verticalButtons(mylist1)
two = verticalButtons(mylist2)
button_columns = widgets.HBox([one.verticalbuttons,two.verticalbuttons])
display(button_columns)
结果如下:

有什么想法吗?我甚至不需要代码,只是想知道如何处理它


谢谢。

您能在全局范围内创建一个计数器来存储按钮点击吗?然后使用按钮的
点击
指令创建运行的函数?函数可以读取按钮的文本(当按钮实例传递给观察到的函数时),然后递增相应的计数器。此函数需要在类之前创建,因此可以将其链接到
create\u buttons
方法中的按钮。