Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the book, wxPython in Action (page 65), the following code shows how to bind an event to a frame (self) and to a button. In the case of the frame event (wx.EVT_CLOSE), no source argument is specified because the event is being bound to the object refenced as "self". The source argument is specified for the button binding because it is invoked as self.Bind. In examples I have seen elsewhere, however, the button event is bound to the button as button.Bind(wx.EVT_BUTTON,self.OnEvent,button). I have a few questions:

1) is it better to bind the button event as "self.Bind(event,handler,button)"
2) or as "button.Bind(event,handler)"
3) or as I have seen elsewhere, "button.Bind(event,handler,button)

And if the preferred method is #3, is it necessary to include the source argument when the source is implied as the object for which Bind is being invoked?

def __init__(self, parent, id): 
    wx.Frame.__init__(self, parent, id, 'Frame With Button', 
            size=(300, 100)) 
    panel = wx.Panel(self, -1)                               
    button = wx.Button(panel, -1, "Close", pos=(130, 15), size=(40, 40)) 
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)   
    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.