Search code examples
pythonevent-handlingwxpython

Do I have to call 'event' in an event handler function in wxpython?


I am not sure my question is clear, so I'm going to explain a little more.

Here is the situation:

class Frame(wx.Frame):
    def __init__(self, title):
        [...]
        self.Bind(wx.EVT_CLOSE, self.onclose)

    def onclose(self, event):
        """
        Close the program
        """
        self.Destroy()

So, in this code, 'event' is useless, and I would like not to call for it then, but I haven't been able to do so. Is there a recommended use of 'event' I am not applying? Is it even possible not to call 'event' ? I have not found a way.

Thanks!


Solution

  • In this case, event is not used, but in other cases, event could be used to know how the function onclose was called; what event caused the function to execute. If your event was caused by a mouse click you could make onClose behave differently from a button click, using the same function.

    event is required because any binding from wx will send an event object to the called function, hence when you cannot use def onclose(self) with accepting the event object.