pygame-ce
Problem
- the pygame-ce package is in pyodide but,:
- https://pyodide.org/en/latest/usage/packages-in-pyodide.html
- https://github.com/pyodide/pyodide/issues/289
- https://pyga.me/docs/ >
# Example file showing a circle moving on screendoesn't yet work if pasted into a JupyterLite notebook cell
Proposed Solution
- how to run pygame-ce with JupyterLite notebooks
Additional context
did you try that loop model instead ? https://pygame-web.github.io/wiki/python-wasm/#main-loop-example-must-be-asynchronous
This doesn't seem to work:
# Example file showing a circle moving on screen, modified
import asyncio
import pygame
# pygame setup
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
dt = 0
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
async def main():
global running
while running:
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# fill the screen with a color to wipe away anything from last frame
screen.fill("purple")
pygame.draw.circle(screen, "red", player_pos, 40)
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
player_pos.y -= 300 * dt
if keys[pygame.K_s]:
player_pos.y += 300 * dt
if keys[pygame.K_a]:
player_pos.x -= 300 * dt
if keys[pygame.K_d]:
player_pos.x += 300 * dt
# flip() the display to put your work on screen
pygame.display.flip()
# limits FPS to 60
# dt is delta time in seconds since last frame, used for framerate-
# independent physics.
dt = clock.tick(60) / 1000
asyncio.run(main())
# pygame.quit()
- [ ] Create a pygame.ipynb example notebook
Is is very unlikely to work in jupyterlite. To run pygame in the browser you likely need to run pyodide in the main-thread. In lite, kernels typically run in a webworker, therefore this will not work.
There might be a theoretical solution using an offscreeen-canvas, but even that is likely not working
Which rendering engine would work better with pyodide? Something wgpu-based?
There are many educational resources for pygame, which would work in pyodide on Chromebooks
On Wed, Jun 4, 2025, 4:38 AM Thorsten Beier @.***> wrote:
DerThorsten left a comment (jupyterlite/pyodide-kernel#195) https://github.com/jupyterlite/pyodide-kernel/issues/195#issuecomment-2939133469
Is is very unlikely to work in jupyterlite. To run pygame in the browser you likely need to run pyodide in the main-thread. Pyodide is running in a webworker therefore this will not work.
There might be a theoretical solution using an offscreeen-canvas, but even that is likely not working
— Reply to this email directly, view it on GitHub https://github.com/jupyterlite/pyodide-kernel/issues/195#issuecomment-2939133469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMNSZNZSIIETODF2NDHK33B2V77AVCNFSM6AAAAAB6R4DW6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMZZGEZTGNBWHE . You are receiving this because you authored the thread.Message ID: @.***>
Which rendering engine would work better with pyodide? Something wgpu-based?
There are many educational resources for pygame, which would work in pyodide on Chromebooks …
its not about pyodide itself. In jupyterlite the kernels run in a webworker. That makes things more complicated