Introduction

Installation

Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Browser interface

Brython-specific built-in modules

Working with Brython

Brython for Firefox OS

Cookbook

 

Problem

Enable / disable an event on an element

Solution

from browser import document
from browser import alert

def myevent(ev):
    alert('it works !')

def counter():
    alert('%s event(s) attached to "click"'
        %len(document['myblock'].events('click')))

@document['bind_click'].bind('click')
def bind_click(ev):
    document['myblock'].bind('click', myevent)
    counter()
    document['mymessage'].text='event is bound, just click to see...'

@document['unbind_click'].bind('click')
def unbind_click(ev):
    print(document['myblock'].events('click'))
    if document['myblock'].events('click'):
        document['myblock'].unbind('click', myevent)
        counter()
        document['mymessage'].text='click disabled'

waiting to do something