在散景中使用 on_change() 方法(python 代码)

Using on_change() method in bokeh (python code)

以下代码的目的是根据 TextInput() 框中的输入生成 TextInput() 框,并从新的 TextInput() 框中提取值 问题是我很难理解 on_change() 函数。在第一个框中输入后,我得到了一些框(我将其称为 'generated box')。 每当我输入生成的框时,我都能打印 'Printing',所以我知道 on_change() 方法在所有生成的框中循环工作,但我无法提取任何用户输入生成的框数。

from bokeh.client import push_session
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, TextInput
from bokeh.layouts import gridplot, row, column 
curdoc().clear()
NR=TextInput() #Input no. of rows in this
N=[] #stores the TextInput boxes NR times
value=0
def PushSes(x):
      rowe = row(x)
      curdoc().add_root(rowe)

def update(attr,new,old):
      global value
      global N
      value1= int(NR.value)
      for i in range (value1):
            N.append(TextInput()) #N stores the TextInput boxes

      for i in N:
            i.on_change('value',update1)

      curdoc().clear()
      PushSes(N)

def update1(attr,new,old):
      print('Printing')
NR.on_change('value',update)
val=[] #stores value from the first row
session=push_session(curdoc())
PushSes(NR)
session.show()
session.loop_until_closed()

Bokeh 在调用回调时传递给 update1new 参数具有文本框的新值。

解决了问题 -

def update1(attr,new,old):
      print('Printing')
      print(old)

在循环中 old 具有值并按键入顺序打印。感谢@bigreddot 的提示。