JavaScript Engine Documentation

The methods described in this page make it easy to interact with the JavaScript Engine.

class tkinterweb.js.JSEngine(html, document, backend)

Access this class via the javascript property of the HtmlFrame and HtmlLabel widgets.

New in version 4.12.

Variables:
  • html – The associated TkinterWeb instance.

  • document – The associated HTMLDocument instance.

  • backend – The scripting backend in use. May be pythonmonkey or python. New in version 4.19.

  • sandbox – If True, scripts running Python code will lose access to built-in objects. Default False. New in version 4.19.

register(name, obj)

Register new JavaScript object. This can be used to access Python variables, functions, and classes from JavaScript (eg. to add a callback for the JavaScript alert() function or add a window API).

JavaScript must be enabled.

Parameters:
  • name (str) – The name of the new JavaScript object.

  • obj (anything) – The Python object to pass.

Raises:

RuntimeError – If JavaScript is not enabled.

eval(expr, _this=None)

Evaluate JavaScript code.

JavaScript must be enabled.

Parameters:

expr (str) – The JavaScript code to evaluate.

Raises:

RuntimeError – If JavaScript is not enabled.