How to know when items are added or removed from the TokenBox library?

I’m trying to figure out how to use the TokenBox library (https://anvil.works/library/tokens). I need an event to trigger when items are added or removed from the TokenBox .
I read its possible to pass in a callback function but I can’t figure out how it’s done.

That component has an add_callback and a remove_callback. I haven’t used those personally, but they need to be set at runtime, so I imagine something like:

self.token_box1.add_callback = self.add_callback

Where self.add_callback is a function in the current form, of the form:

def add_callback(self, token):
    pass
1 Like

Thanks! I first tried passing the callback function in as an argument: self.token_box1.add_callback(self.add_callback). That was obviously the wrong way.