Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created November 14, 2022 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbueno/07c34a93b64f35e00ea3fbd091d5a093 to your computer and use it in GitHub Desktop.
Save jsbueno/07c34a93b64f35e00ea3fbd091d5a093 to your computer and use it in GitHub Desktop.
brython "hello world" showing the easy-to use DOM integration that is lacking on other python-on-browsers.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
</head>
<body onload="brython(1)">
<div id="main"></div>
<script type="text/python">
from browser import document
from browser.timer import set_timeout
import random
counter = 0
def muda():
global counter
colors = "yellow blue red green".split()
document["main"].style["color"] = random.choice(colors)
document["main"].innerHTML = str(counter)
counter += 1
set_timeout(muda, 200)
muda()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment