I'm creating a couple of swing JButtons buttons in a loop in Jython. On press, each button should call the same function, but with one different parameter. I'm having trouble passing any parameters outside of self, and event.
This works:
for x in range(0,3):
name = JButton(str(x))
name.actionPerformed = self.foo
def foo(self, event):
print "I work."
Somehow event magically is passed to the method.
This doesn't:
for x in range(0,3):
name = JButton(str(x))
name.actionPerformed = self.foo(x)
def foo(self, event, number):
print "I don't work."
print str(number)
The issue as I see it, it that I'm not when I add any argument, I no longer pass an event and I end up with an error telling me "foo() takes exactly 3 arguments (2 given)". I get that, but how can I extract the event from the button?