Search code examples
wxpython

wxpython, passing data to a function in self.Bind


I'm having trouble finding the answer to this to know if its possible. Ive looked in the wxpython demo and done some googling to no avail.

how do I pass some sort of data to the function call when I am binding actions?

for example

self.Bind(wx.EVT_MENU, self.DoThis, item1)

self.Bind(wx.EVT_MENU, self.DoThis, item2)

I have a set of menu options that I want to be handled by the same function (DoThis), but need to pass that function some data because its output depends on which menu item was selected.

I know I can just bind each menu item to a different function so could just replicate it a bunch of times, but for the sake of clarity and length of code, it would be much simpler to handle it all in the same function, because I have about a dozen menu items. Is this even possible? Thanks


Solution

  • a related question is Is it possible to pass arguments into event bindings?. This can do it by passing arguments to callback, as you can see to passing arguments to callbacks.