What I tried:
class ButtonCallback:
def __init__(self, button, callback):
self.set_callback(callback)
button.on_click(self.callback_fn)
def callback_fn(self, event ):
pass
def set_callback(self, callback):
self.callback_fn = callback.__get__(obj)
def initial_function(obj, event): print("Initial function executed: ", event, "\n")
def new_function(obj, event): print("New function executed: ", event, "\n")
button = pn.widgets.Button(name='Click me!')
button_callback = ButtonCallback(button, initial_function)
button_callback.callback_fn( None)
button
this indeed executes the initial function. Then
button_callback.set_callback(new_function)
button_callback.callback_fn( None)
this executes the new function, however clicking the button
still executed the original function.
Any way to make this work?