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
 

Testing and debugging

Interactive test

The Brythons site, or its mirror available for download, include a console where you can test Python code.

Please note that the namespace is not refreshed when you click on "run", you must reload the page for that.

For debugging and testing Brython, a number of test scripts are grouped in the directory tests ; you can access them by clicking the link "Test pages" in the console, then select the different tests and run them.

Debugging scripts

Whatever the debugging level, syntax errors are reported in the browser console (or at the place defined by sys.stderr)

For instance, the code

x = $a

generates the message

SyntaxError: unknown token [$]
module '__main__' line 1
x = $a
    ^

By setting the debugging level to 1 in the call to function brython(debug_mode), the exceptions raised at runtime and not caught by an except also produce an error message, as close as possible to the one generated by Python3.

This code :

x = [1, 2]
x[3]

generates :

IndexError: list index out of range
module '__main__' line 2
x[3]