how to create an event listener in python