微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当用户更改文本字段时,ipyvuetify捕获文本字段的用户输入值

如何解决当用户更改文本字段时,ipyvuetify捕获文本字段的用户输入值

我正在使用vuetify来捕获用户的输入,如下所示:

enter image description here

%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)

我要解决的问题:

  1. 可视化还可以,但是更改输入中的值时,按钮的事件处理程序中的v_application.value不会捕获该值。不过,在第二行:v_nr.value='The value was changed successfully' 中,该值已通过编程方式更改。当用户更改输入文本时,您如何编码以使输入更改输入文本的值?
  2. 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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。