【发布时间】:2019-01-20 17:52:41
【问题描述】:
我构造了一个链接到 MySQL 的函数,它返回给定父 ID 的子列表。我想使用 ipywidgets 输出这个孩子的列表。
我无法将函数链接到 ipywidgets。到目前为止,我有:
> from ipywidgets import widgets
>
> text1 = widgets.Text()
> text2 = widgets.Text()
> button = widgets.Button(description = 'Run')
> display(text1)
> display(button) display(text2)
>
> idnum = text1.value
> text2.value= list_children(idnum)
>
> button.on_click(list_children)
函数如下:
> def list_children(parentid):
> value = parentid
> parent_80 = session.query(Parent).get(value)
> parent_80_children= parent_80.children
> childrenlist=[]
>
> for i in parent_80_children:
> childrenlist.append(i.UWI)
>
> return childrenlist
我不断收到以下错误:
AttributeError: 'NoneType' 对象没有属性 'children'
因为它打破了这一行:
parent_80_children= parent_80.children
如果我运行 python 单元,该函数是正确的,所以我知道它正在工作,但是当我尝试单击小部件框“运行”时它会中断。不知何故,函数和小部件框之间没有链接。
我希望在单击“运行”小部件按钮时得到如下输出:
- 1771860100
- 1771860200
- 1771860300
减去要点。
感谢任何输入。
【问题讨论】:
标签: function user-interface button display ipywidgets