Trying to understand ETO button bound method

I was reading this post on the rhino3d website and I was having problem understanding the way the bound method as described in the post is structure, copied below:

The bound method, listed later in the calss definition is run if the button is clicked.

    # Close button click handler
    def OnOKButtonClick(self, sender, e):
        if self.m_textbox.Text == "":
            self.Close(False)
        else:
            self.Close(True)

where does the sender and e input coming from? Do I ever have to change them and call/assign them?

self.m_button.Click += self.OnButtonClick

also on the subject, in the line above, it is explained in the post that:

an action is commonly attached through the .Click event. Use the += syntax as shown below to bind the action to button.

I’m not an expert in Python and could not understand why +=, which usually means equal to self in addition to *, can here used to bind action to a button, which is not that big of a deal, but do I ever have to use a different syntax for button binding in a specific scenario?

Thank you so much!

Hi @Jun_Wang,

sender and e are standard parameters that are passed to any event handler, where:

  • sender contains a reference to the control/object that raised the event .
  • e contains the event data. The contents of e depend on the event that was triggered.

More info: Handling and Raising Events - .NET | Microsoft Learn

This is true. The sample code is adding an event handler (e.g. delegate) to the event’s list of handlers. An event can notify more than one event handler.

– Dale

1 Like

Thank you for answering this noob question, got some studying to do apparently!

Hi @Jun_Wang,

Using Eto in Python certainly doesn’t fall into the ‘noob’ category…

– Dale