python callback handlerswhich are later run with embedding interfaces in response to gui events you can study tkinter' implementation in the python source distribution for more detailsits tk library interface logic makes it somewhat challenging readbut the basic model it employs is straightforward registration implementation this section' and python files demonstrate the coding techniques used to implement explicitly registered callback handlers firstthe file in example - implements interfaces for registering python handlersas well as code to run those handlers in response to later eventsevent router the route_event function responds to an event by calling python function object previously passed from python to callback registration the register_handler function saves passed-in python function object pointer in global variable python scripts call register_handler through simple cregister extension module created by this file event trigger to simulate real-world eventsthe trigger_event function can be called from python through the generated module to trigger an event in other wordsthis example uses both the embedding and the extending interfaces we've already met to register and invoke python event handler code study example - for more on its operation example - pp \integrate\embed\regist\cregister #include #include /***********************************************/ code to route events to python object */note that we could run strings here instead */***********************************************static pyobject *handler null/keep python object in *void route_event(char *labelint countchar *crespyobject *args*pres/call python handler *args py_buildvalue("(si)"labelcount)pres pyeval_callobject(handlerargs)py_decref(args)/make arg-list */applyrun call */add error checks *registering callback handler objects