Tkinter does not pass any parameter to the callbacks -
so, you have to pass a different callable object to each button.
The good news is that you don't need to implement as many functions
as there are buttons: you can create short anonymous functions
that just add informationa bout which button was clicked to the
real callback. These anonymous functions, created with the lambda
keyword
can be created when connecting the buttons by filling in the command
option:
self.button1 = Tkinter.Button(self,text=u"Convert Decimal to Binary", command=lambda: self.OnButtonClick("b1") )
self.button1.grid(column=1,row=1)
self.button2 = Tkinter.Button(self,text=u"Convert Binary to Decimal", command=lambda: self.OnButtonClick("b2") )
self.button2.grid(column=1,row=2)
This way, the OnButtonCLick method will have the strings "b1" and "b2" respectively as
the second parameter on the call (the first parameter will be the reference to the
object itself - self
)
If you want to pass a reference to the buttons themselves, you have to configure
their command
in a subsequent line, after they've been created:
self.button1 = Tkinter.Button(self,text=u"Convert Decimal to Binary")
self.button1["command"] = lambda: self.OnButtonClick(self.button1)
...