Is it possible to replace a panel button callback function with another function?

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?

It occurred to me to add a level of indirection; this works:

class ButtonCallback:
    def __init__(self, button, callback):
        self.set_callback(callback)
        button.on_click(self.called_fn)

    def called_fn( self, event ):
        self.callback_fn( event )

    def callback_fn(self, event ):
        pass

    def set_callback(self, callback):
        self.callback_fn = callback.__get__(self)

Simpler to use a closure:

def mk_replaceable_fn( func=lambda event: print(event) ):
    actual_function = func

    def function(y): return actual_function(y)

    def set_actual_function(new_actual_function ):
        nonlocal actual_function
        actual_function = new_actual_function

    return function, set_actual_function

func, replace_func = mk_replaceable_fn()
func(5)
replace_func( lambda event: print("Fired") )
func(5)