Skip to main content
 首页 » 编程设计

python之Dash 中的按钮没有 "click"作为事件

2025年05月04日998°冷暖

我在布局中添加了一个按钮。当我尝试为其编写回调时,出现以下错误:

dash.exceptions.NonExistantEventException:  
Attempting to assign a callback with 
the event "click" but the component 
"get_custom_vndr" doesn't have "click" as an event. 
 
Here is a list of the available events in "get_custom_vndr": 
[] 

这是我将它添加到我的布局中的方式:

app_vndr.layout = html.Div([ 
    html.Button( 
        '+', 
        id='get_custom_vndr', 
        type='submit' 
    ) 
]) 

这里是给出上述错误的回调函数:

@app_vndr.callback( 
    dash.dependencies.Output('overlay', 'className'), 
    events=[dash.dependencies.Event('get_custom_vndr', 'click'), 
            dash.dependencies.Event('add_vndr_id_submit', 'click')]) 
def show_input(b1_n, b2_n):     
    if b1_n>0: 
        return '' 
    elif b1_n>0: 
        return 'hidden' 

当我将按钮添加到我的布局时,我错过了什么吗?或者当我尝试编写回调时?

我得到了它的工作

dash.dependencies.Input('get_custom_vndr', 'n_clicks') 

但是我想对相同的输出和 n_clicks 事件使用两个按钮,我需要尝试通过比较每个按钮的当前 n_clicks 与之前的 n_clicks 来找出点击了哪个按钮,这似乎就像一个非常 hacky 的方式来做到这一点。

请您参考如下方法:

Dash 不允许对同一个 Output() 进行多次回调