I have no experience with this. Perhaps you could look at how the highgui callback setters do it, or rather, how the bindings generation code adapts these. mouse and trackbar callbacks can be set, and the library will call the given python functions that were passed.