def on_button(callback, args=(), buttons=(LEFT, MIDDLE, RIGHT, X, X2), types=(UP, DOWN, DOUBLE)):
if not isinstance(buttons, (tuple, list)):<EOL><INDENT>buttons = (buttons,)<EOL><DEDENT>if not isinstance(types, (tuple, list)):<EOL><INDENT>types = (types,)<EOL><DEDENT>def handler(event):<EOL><INDENT>if isinstance(event, ButtonEvent):<EOL><INDENT>if event.event_type in types and event.button in buttons:<EOL><INDENT>callback(*args)<EOL><DEDENT><DEDENT><DEDENT>_listener.add_handler(handler)<EOL>return handler<EOL>
Invokes `callback` with `args` when the specified event happens.