【发布时间】:2022-01-16 09:23:39
【问题描述】:
我试图在单击按钮时获取组合框的值,并在按钮单击处理程序中处理该值。但是,combobox.v_model 似乎只有在按钮单击处理程序退出后才能正确更新。
这是我所做的(代码如下):
- 当小部件出现时,在组合框中输入字符串 'xxx'
- 随后单击按钮并获取 combobox.v_model 的值
- 预期检索“xxx”,但检索到“”(空字符串)
有没有办法在输入后立即通过单击按钮来检索组合框内容?
注意:如果在单击按钮之前按下“Enter”/“TAB”,则一切正常,但如果在组合框中输入后立即按下按钮,则不会。
import ipyvuetify as vue
name = ''
# vuetify combobox and button
combobox = vue.Combobox(label="Enter name", v_model="", items=[], autofocus=True)
btn = vue.Btn(children=['Process name'])
component = vue.Row(children=[
vue.Col(children=[combobox]),
vue.Col(children=[btn])
])
# --- event handler -------------------------
# Some processing of the combobox input needs to happen
# on a button click, but v_model is not updated
def on_button_clicked(widget, event, data):
print(f"btn clicked: {combobox.v_model=}")
name = combobox.v_model
print(f'btn clicked: {name=}')
# do some processing with name here
btn.on_event("click", on_button_clicked)
display(component)
【问题讨论】:
标签: python jupyter ipyvuetify