Simon Bhattacharya edited this page Sep 13, 2013 · 2 revisions

Quick how-to about event handling


Events in pyjamas are handled by adding an event listener. In pyjamas, an event listener is either a function or an object with a specially-named method, like onClick.

To register an event handler call the appropriate method:

myButton = Button()

It's important to realize that pyjamas doesn't create bound methods automatically the way that python does, so you can't just pass self.myOnClick to addClickListener(). However, if you use getattr() to get the method address, pyjamas does create the equivalent of a bound method, so you can get this effect like this:

myButton.addClickListener(getattr(handler, "myOnClick"))

This useful tip should help you make your event listeners easily and painlessly - enjoy!

See Also

Event Handling Tutorial