以下代碼的目的是基於TextInput()
框中的輸入生成TextInput()
框,並從新框TextInput()
中提取值 問題是我有困難瞭解on_change()
功能。在輸入第一個框後,我會得到一些框(我將稱之爲'生成框')。 我可以打印'打印',只要我輸入一個生成的框,所以我知道on_change()
方法在所有生成的框循環工作,但我一直無法提取任何生成的框中的用戶輸入。在散景中使用on_change()方法(python代碼)
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()