Is there a way to handle double-click as single-click?

Rather than debounce the handlers in form code, you might consider overriding the Button/Link classes add_event_handler method

from functools import wraps
from time import sleep

orig_add_event_handler = Button.add_event_handler
DELAY = 0.3

def debounce(fn):

    clicks = []
    
    @wraps(fn)
    def wrapped(*args, **kws):
        if clicks:
            return
        clicks.append(True)
        try:
            fn(*args, **kws)
        finally:
            sleep(DELAY)
            clicks.pop()

    return wrapped

def add_event_handler(self, event, handler):
    if event == "click":
        handler = debounce(handler)
    return orig_add_event_handler(self, event, handler)

Button.add_event_handler = add_event_handler
2 Likes