问题描述
我正在使用vuetify来捕获用户的输入,如下所示:
%pip install ipyvuetify
%pip install ipywidgets
import random
import ipywidgets as widget
from ipywidgets import VBox
import ipyvuetify as v
v_nr = v.TextField(label='Enter a number here:',placeholder='Enter here data',value = '2342354')
v_nr.value='The value was changed sucssefully'
v_btn_load = v.Btn(class_='mx-2 light-red darken-1',children=['the data'])
w_Output = widget.Output()
infostring = ' this is the infostring there'
other_info = v.Html(tag='p',children=[infostring])
Output = VBox([w_Output])
total_widgets = v.Col(children = [v_nr,v_btn_load,w_Output,other_info])
def on_click_v_btn_load(widget,event,data):
with w_Output:
w_Output.clear_output()
n = random.random()
display(str(n) + ' :' + v_nr.value)
other_info.children.append(' APPEND ')
v_btn_load.on_event('click',on_click_v_btn_load)
container = v.Container(children=[total_widgets])
display(container)
我要解决的问题:
- 可视化还可以,但是更改输入中的值时,按钮的事件处理程序中的v_application.value不会捕获该值。不过,在第二行:
v_nr.value='The value was changed successfully'
中,该值已通过编程方式更改。当用户更改输入文本时,您如何编码以使输入更改输入文本的值? -
other_info.children.append(' APPEND ')
似乎无效,但均未报告任何错误。期望的是,每次单击按钮时都会在单词GORILA后面添加,并非如此。
有什么想法吗? 谢谢。
注意:为方便起见,还包括%pis。
解决方法
v_nr访问内容的属性是“ v_model”,而不是“值”。
只需更改它即可:
import random
import ipywidgets as widget
from ipywidgets import VBox
import ipyvuetify as v
v_nr = v.TextField(label='Enter a number here:',placeholder='Enter here data',v_model = '2342354')
v_nr.v_model='The value was changed sucssefully'
v_btn_load = v.Btn(class_='mx-2 light-red darken-1',children=['the data'])
w_Output = widget.Output()
infostring = ' this is the infostring there'
other_info = v.Html(tag='p',children=[infostring])
Output = VBox([w_Output])
total_widgets = v.Col(children = [v_nr,v_btn_load,w_Output,other_info])
def on_click_v_btn_load(widget,event,data):
with w_Output:
w_Output.clear_output()
n = random.random()
display(str(n) + ' :' + v_nr.v_model)
other_info.children.append(' APPEND ')
v_btn_load.on_event('click',on_click_v_btn_load)
container = v.Container(children=[total_widgets])
display(container)