1

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

4

1 回答 1

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)
于 2020-10-28T18:38:40.333 回答