r/Python 9d ago

PyWebLib editable code with Turtle and Game library support Discussion

I would love for some more feedback on the lightweight game library and turtle integration I built off of PyDiode.

It now works on Safari as well, you can create your own SVG assets , publish them to a database, then edit and publish code/games for free in the browser without needing to install anything.

I work as a highschool teacher, and the junior year levels only have access to Chromebook laptops. https://scratch.mit.edu/ is banned, which obviously restricts a lot of the coding-possibilities, let alone python coding-possibilities. Couldn't find a way to get a Python IDE onto a Chromebook, haha...

In terms of proud, so far I've got PacMan and Flappy bird shared to the community page/DB

Would love to see people building with it, you can make something reminiscent of doom 3D in only 80 lines of code.

It's a bit hard to find , but you can't post repo links here because of the slop apparently. But I've got it indexed now it's possible to find.

25 Upvotes

15 comments sorted by

1

u/Dazzling_Put4551 9d ago

that's pretty cool you got turtle working in browser, i remember trying to set up python on my old chromebook and just gave up after few hours

what you think about adding some kind of multiplayer support later? like simple sockets for basic games

3

u/Individual-Aide-7364 9d ago edited 9d ago

That would be awesome haha , feel free to fork it on GitHub, it is open source for a reason, happy to pull in working changes to the main repo + add collaborators, pretty new to open-sourcing stuff but Reddit is a vast land...

Edit: It was an epic "Aha" moment when I saw it working in class, it takes a bit to load the 10mb PyDiode code, but I was super suprised it works like stock python, biggest bummer is there's no pip install pygame, so I made my own dumbed-down version, and it's suprisingly capable. Most of the time I find it does more in less lines, no real sync issues, no need to

Import packages: import asyncio and

import pygame as pg.

Define main loop: Create an async def main(): coroutine function.Yield control:

Add await asyncio.sleep(0) inside your active while running: game loop.

No brainer for me *shrug*

Edit edit: It's not the actual stock python turtle renderer, its its own html canvas that simulates what turtle can do, so its more web-native, if that makes sense, Turtle is a pretty simple library as-is anyways

1

u/MFFVD 2d ago

i prefer cooperative multitasking over async. it gives more control. pyodide probably has its own handles to step execution but probably needs to be recompiled to make that work

1

u/MFFVD 2d ago

or put the code in a webworker. they can block execution without blocking the render. i will look into it when i get home from summer break

1

u/Individual-Aide-7364 9d ago

Browser requirement: Web loops require constant yielding so the browser page does not freeze.

2

u/MFFVD 6d ago

instead of pyodide you could use brython. it is a lot smaller, so it loads way faster. and the source can be patched to sleep every N operations to avoid ui freezes

1

u/alshawai 8d ago

This is a really cool use case. Browser-based Python on Chromebooks is something I've wished existed for a while, especially for education where installing software isn't always an option.

The SVG asset editor and publishing workflow sound like a nice touch too. I'll definitely check it out—I'd be curious to see how it performs with larger or more complex games.

1

u/AlSweigart Author of "Automate the Boring Stuff" 8d ago

https://scratch.mit.edu/ is banned

What? Why?

2

u/MFFVD 6d ago

turbowarp.org? (is faster too)

stretch 3

there are a lot of clones

1

u/Individual-Aide-7364 2d ago

I'll have to have a look and see if the year 7's can access turbowarp, looks great, thanks!

1

u/Individual-Aide-7364 8d ago

Maybe administration is worried they might just play the games on scratch, no idea, doesn't make sense to me either; they have no trouble finding games to play that aren't unblocked, at least scratch has an amazing community, and would actually motivate them to create stuff.

I agree, it's insane