Introduction

Installation

Limitations of the "file" protocol

Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Brython packages

Browser interface

Introduction - DOM API
Creating a document
Accessing elements
Attributes, properties and methods

Events
Mouse events
Keyboard events
Focus events
Drag events

Query string

Interactions with Javascript

Brython-specific built-in modules

browser
browser.aio
browser.ajax
browser.html
browser.local_storage
browser.markdown
browser.object_storage
browser.session_storage
browser.svg
browser.template
browser.timer
browser.webcomponent
browser.websocket
browser.worker

Widgets
browser.widgets.dialog
browser.widgets.menu

interpreter
javascript

Working with Brython

Execution options
Testing and debugging
Deploying an application

Cookbook

Hello world !
Insert content in an element
HTML markup (bold,italic...)
HTML table
Bind and unbind events
Handle options in a SELECT
Drag and drop
Get the content of an element
Read the content of a file
Store objects locally
Example of onmouseover
 

The package browser groups the built-in Brython-specific names and modules

browser.alert(message)
a function that prints the message in a pop-up window. Returns None

browser.bind(target, event)
a function used as a decorator for event binding. Cf. section events.

browser.confirm(message)
a function that prints the message in a window, and two buttons (ok/cancel). Returns True if ok, False if cancel.

browser.console
an object with methods to interact with the browser console. Its interface is browser-specific. It exposes at least the method log(msg), which prints the message msg in the console

browser.document
an object that represents the HTML document currently displayed in the browser window. The interface of this object is described in section "Browser interface"

browser.DOMEvent
the class of DOM events

browser.DOMNode
the class of DOM nodes

browser.is_webworker
boolean indicating if the current script is executed in a Web Worker

browser.load(script_url)
Load the Javascript library at address script_url.

This function uses a blocking Ajax call. It must be used when one can't load the Javascript library in the html page by <script src="prog.js"></script>.

The names inserted by the library inside the global Javascript namespace are available in the Brython script as attributes of the window object.

browser.prompt(message[,default])
a function that prints the message in a window, and an entry field. Returns the entered value ; if no value was entered, return default if defined, else the empty string

browser.run_script(src[, name])
this function executes the Python source code in src with an optional name. It can be used as an alternative to exec(), with the benefit that the indexedDB cache is used for importing modules from the standard library.

browser.window
an object that represents the browser window (see the MDN documentation)