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
 

interpreter

This module provides classes to open a Python interactive interpreter in a page. It is used by the console and the editor of the site brython.info.

Classes

Interpreter(element=None, title="Interactive Interpreter", globals=None, locals=None, rows=30, cols=120, default_css=True)

  • if element is None, the interpreter is opened in a new dialog box (cf. module browser.widgets.dialog).

    Otherwise, element can be an existing DIV with attribute contenteditable in the page, or the attribute id of an existing content-editable DIV.
  • if element is None, title is the title of the dialog box
  • dictionaries globals and locals are the environment where the interpreter commands are executed (by default, empty dictionaries)
  • rows and cols are the dimensions in number of characters
  • default_css specifies if the CSS stylesheet provided by the module should be used. If the value is False, the styles defined in the HTML page are used (cf. "CSS style" below)

from interpreter import Interpreter

Interpreter()

Inspector(title="Frames inspector", rows=30, cols=120, default_css=True)
Opens a dialog box with an interactive interpreter running in the program execution frames. This can be used for debugging purposes.

Note that opening an inspector does not block program execution, but the namespaces used in the inspector represent the state of the frames when it was opened.

For instance, in this example, the value of y in frame f is 8, not 9:

from interpreter import Inspector

def f(x):
  y = 8
  Inspector()
  y = 9

f(5)

CSS style

If an interpreter is opened in an existing DIV, the HTML stylesheet is used.

Otherwise, if argument default_css is True (default), the following stylesheet in inserted in the page:

.brython-interpreter {
    background-color: #000;
    color: #fff;
    font-family: consolas, courier;
    caret-color: #fff;
    overflow-y: auto;
    overflow-x: hidden;
}

@keyframes blinker {
  50% {
    opacity: 0;
  }
}

pre{
    display:inline;
}

To customize the interpreter look, pass default_css=False and redefine the CSS class brython-interpreter. The most straightforward is to copy-paste the stylesheet above and edit it.