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")))

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

document["bind_click"].bind("click", bind_click)

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

document["unbind_click"].bind("click", unbind_click)

waiting to do something