q5play in Python?!
Switching to Python curriculum? You'll still be able to teach q5play!
q5.js and q5play can now be used with Python! 🐍
Check out the q5play + Python demo. 👀 Here’s the code:
await Canvas()
world.gravity.y = 10
ball = Sprite.new()
ball.diameter = 50
ball.img = '🤪'
groundA = Sprite.new()
groundA.x = -120
groundA.width = 220
groundA.rotation = 30
groundA.physics = STATIC
groundB = Sprite.new()
groundB.x = 120
groundB.width = 220
groundB.rotation = -30
groundB.physics = STATIC
def update():
background('skyblue')
text('click to jump!', 0, -50)
if mouse.presses():
ball.vel.y = -5How is it possible to use a JavaScript library in Python? Well, it’s not. Ha!
It uses the Brython transpiler, which converts Python to JavaScript on the fly at runtime, right in the web browser. Simply load a Python script in your HTML with the type set to “q5-python” and q5.js will use Brython to run it!
<script type="q5-python" src="sketch.py"></script>But note, this is just a proof-of-concept release.
I’ll add error reporting soon!
I plan on translating the entire Learn q5play interactive textbook to Python.
So if your school is requiring you to switch to Python curriculum next year, you’ll still be able to teach q5play!


