Search code examples
wxpythonwxglade

wxpython: multiple instances of a stock ID


Is it possible to create a wxpython Frame with several instances of the same stock ID?

I wish my application to include several "APPLY" buttons, and found quite convenient to use ID_APPLY as themed icons and labels are pre-defined. Each button has a specific handler. However all bound handlers are triggered by any of these buttons.

Is there a way to achieve this or is my approach doomed by the way handlers are bound to IDs internally?


Solution

  • It's doomed. You would be better off creating a subclass of wx.Button that has the same look and feel as the button you want. Then you can just create instances of that button and bind them to whatever event handler you want.

    On the other hand, if you can set each button to have a unique name, you could use an if statement in the one event handler to determine which button is which and call a different method based on that. See http://www.blog.pythonlibrary.org/2011/09/20/wxpython-binding-multiple-widgets-to-the-same-handler/ for more details. I suspect that the wx.ID_APPLY will override the name of the widget, but I'm not sure. Worth a try anyway.