Search code examples
pythoneventswxpythonwxwidgets

event handling in wxpython


In wxpython, is it better to handle events by creating a separate function for each event handler (say a separate function for every single button click) or to create one large button_handler, and then determine the button clicked from there?

Basically, I am wondering if it is more resource intensive to have many different events being watched for each separate thing, or just one big event that will figure out which one was clicked when it was fired.


Solution

  • If I have three buttons that do radically different things, then I want different event handlers for them because I find that easier to debug. If they're all print buttons with slightly different formatting options applied, then I'll hook them all up to the same handler and use event.GetEventObject() to figure out which one called. The few times I've had multiple events handled by the same handler was when I had a toolbar button and a menu item both call the same thing. It has more to do with program flow and ease of debugging and that just comes with practice.