Questions tagged [brython]

Brython is a browser-integrated Python engine.

Brython stands for Browser's Python. It's goal is to replace JavaScript with Python as the scripting language for web browsers. It is composed of a lightweight run-time translation layer that brings many of Python's syntax niceties directly to the browser, as simple as using a <script type="text/python"> tag.

Some possible uses are

  • Creating simple document elements,
  • Drag and drop elements
  • 3D navigation
  • Geolocation
  • Charts and graphs

For more examples visit the home page and refer to the gallery.

Brython is open source and the source code is available here. Documentation can be found at http://www.brython.info/doc/en/index.html.

108 questions
1
vote
0 answers

How can I trigger a key event only after another key event has been triggered?

I am a student learning Python, it would be great if you guys can help me out with this. This is a temporary minimum code segment, window1 is a premade variable that creates a rectangle outside the function. def key_pressed(event): if event.key…
unbenannt
  • 11
  • 1
1
vote
1 answer

How can I load a JSON file in Brython?

I am working on a page with Brython, and one thing I would like to do is load a JSON file on the same server, in the same directory. How can I do that? open()? Something else? Thanks,
Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
1
vote
1 answer

Brython equivalent of `.bind(this)`

In Javascript, you often need to provide context to a function by passing calling .bind(this) before passing it on. I appreciate that in Brython things work a bit differently. But I'm wondering if there is something behind the scenes that provides a…
Rebs
  • 4,169
  • 2
  • 30
  • 34
1
vote
2 answers

Is it possible to have the backend of a website written in python such that I can call a python method and diplay its output?

I am trying to create a website that is centered on an algorithm I developed on python. My vision is that the user would enter something and then receive the output which has been generated with python. I am also trying to call a python file because…
CairoMisr
  • 81
  • 5
1
vote
0 answers

Brython: Refused to load the script....violates the following Content Security Policy directive: "script-src 'self'

I am making a chrome extension in JS but am getting the following errors. I found some similar posts related to it but none of them solved my issue (will explain further down in the post): Refused to load the script…
1
vote
1 answer

How to print out Brython.js output as a DOM element into a specific DOM?

I am using Brython.js I am able to print a loop in HTML browser but as you can see this is adding the output to entire DOM. How can I append the print result into an specific DOM element? For example if I want to print the output into #map, how can…
Behseini
  • 6,066
  • 23
  • 78
  • 125
1
vote
1 answer

Why does the python {:016X} .format() specifier not allow sizes greater than 2**52 in Brython?

I should be able to turn a value up to (2**64)-1 into a zero-padded, 16-hex-nibble string... So why does the below error out when I get up to a size beyond 2**52? >>> a = "{:016X}".format(2**52) >>> a = "{:016X}".format(2**53) Traceback (most recent…
Jimmy Wu
  • 149
  • 7
1
vote
1 answer

How to deliver information to webworker when it requests it

I have a piece of code that needs to execute on a webworker which needs to get feedback from something in the main thread (basically a get operation from a KVS). Unfortunately, I cannot use local storage because it is not accessible from a…
kmindspark
  • 487
  • 1
  • 7
  • 18
1
vote
2 answers

Brython: import the bs4 library and the requests library

I am creating a web application using python with the brython.js library and for my application I need to import the bs4 library and the requests library but I don't know how. Any idea?