在Python + Dash中禁用“提交”按钮30秒钟

我想阻止用户在下面的脚本中按下“提交”按钮30秒钟。我将如何去做呢?这是我的代码当前的外观:


import dash

from dash.dependencies import Input, Output, State

import dash_core_components as dcc

import dash_html_components as html


app = dash.Dash()


app.layout = html.Div([

    dcc.Input(id='my-id', value='initial value', type="text"),

    html.Button('Submit', id='button'),

    html.Div(id='my-div')

])


@app.callback(

    Output(component_id='my-div', component_property='children'),

    [Input('button', 'n_clicks')],

    state=[State(component_id='my-id', component_property='value')]

)

def update_output_div(n_clicks, input_value):

    return 'You\'ve entered "{}" and clicked {} times'.format(input_value, n_clicks)


if __name__ == '__main__':

    app.run_server()

有谁知道我该如何阻止用户按下按钮30秒钟?


预先感谢。


编辑15/08/2018 9:30 GMT对stevepastelan的回应:


import dash

from dash.dependencies import Input, Output, State

import dash_core_components as dcc

import dash_html_components as html


app = dash.Dash()


app.layout = html.Div([

    dcc.Input(id='my-id', value='initial value', type="text"),

    html.Button('Submit', id='button'),

    html.Div([dcc.Interval(

        id='interval-component',

        interval=1 * 3000,  # in milliseconds

        n_intervals=0

)]),

    html.Div(id='my-div')

])


@app.callback(

    Output(component_id='my-div', component_property='children'),

    [Input('button', 'n_clicks')], [Input('interval-component', 'n_intervals')],

    state=[State(component_id='my-id', component_property='value')]

)

def update_output_div(n_clicks,n_intervals, input_value):

    return 'You\'ve entered "{}" and clicked {} times'.format(input_value, n_clicks)


if __name__ == '__main__':

    app.run_server()



跃然一笑
浏览 169回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python