☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

How to disable a button while its callback it running?

Community Supportserver
roinr
roinr

Is it possible to disable a button right after clicking it and then enable it again after the on_click callback is finished?

Here’s a code that will demonstrate the scenario:

from bokeh.models.widgets.buttons import Button
from time import sleep
from bokeh.io import curdoc

# button
button = Button(
    label="Test", 
    button_type='primary', 
    name="button"
)

# callback
def on_button_click():
    button.disabled=True
    sleep(10)
    button.disabled=False

button.on_click(on_button_click)

curdoc().add_root(button)
⌁   Link to post
roinr
roinr

@p-himik
Thanks for your reply!
I modified the code like you said (if I understood correctly) but now the button is disabled but the next_tick function isn’t being invoked.

from bokeh.models.widgets.buttons import Button
from time import sleep
from bokeh.io import curdoc

# button
button = Button(
    label="Test", 
    button_type='primary', 
    name="button"
)

# callback
def on_button_click():
    button.disabled=True

def next_tick():
    sleep(2)
    button.disabled=False

button.on_click(on_button_click)

curdoc().add_root(button)
curdoc().add_next_tick_callback(next_tick)

⌁   Link to post

End of archived discussion · Replies are disabled