source info for buttons

Gabriel Murray gabriel.murray at gmail.com
Wed Jul 5 07:28:16 PDT 2006


In the wxPython book there is an example of a simple button frame (in the
example button.py), where you click on the button and the button label
changes to 'clicked'. If you have two buttons and you want the same result,
i.e. the label to change on whichever button you click, how can you do this
without defining two separate OnClick methods for the two buttons?

For example:

self.button =3D wx.Button(panel, -1, "Hello", pos=3D(50,20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
self.button2 =3D wx.Button(panel, -1, "Hello", pos=3D(150,20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button2)
self.button2.SetDefault()

def OnClick(self,event):
    self.button.SetLabel("Clicked")


######
This will only change the first button regardless of which button was the
source of the click. How do I pass source information to the OnClick method
so that it can change the label of the button that was pressed?
Thanks,
Gabriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200607=
05/9a6419fe/attachment.htm


More information about the wxpython-users mailing list