【问题标题】:ipyvuetify catch the user input value of text Field when user changes it当用户更改文本字段时,ipyvuetify 捕获文本字段的用户输入值
【发布时间】:2021-01-28 00:10:09
【问题描述】:

我正在使用 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)

我想解决的问题:

  1. 可视化效果正常,但是在更改输入中的值时,按钮的事件处理程序中的 v_application.value 不会捕获它。尽管如此,在第二行:v_nr.value='The value was changed successfully' 该值已以编程方式更改。当用户更改输入文本的值时,您必须如何编写代码才能更改输入文本的值?
  2. other_info.children.append(' APPEND ') 似乎不起作用,但也没有报告任何错误。预期的是每次单击按钮时都会附加 GORILA 这个词,但事实并非如此。

有什么想法吗? 谢谢。

注意:为方便起见,包含 %pips。

【问题讨论】:

    标签: python vuetify.js jupyter-lab ipywidgets voila


    【解决方案1】:

    v_nr 访问内容的属性是'v_model',而不是'value'。

    只需更改它即可:

    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)
    

    【讨论】:

    • 可能是我,但我将代码复制到 Jupyter 笔记本中,点击“运行”并没有任何反应??我做错了什么?安德烈亚斯
    猜你喜欢
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多