Your videogame from python to the browser

You can run a python game in the browswer like this one if you use the module pygbag

pip install pygbag

Follow this tutorial to see how to do it.

You have to

  • import asyncio
  • include the while method in an async def main()
  • at the end of the loop you add await asyncio.sleep(0)
  • and out of the loop you call asyncio.run(main())

after this change in the code, from cmd, you run

pigbag snake

(where snake is the folder that contains the main.py code of the game: remember to call the file of the game main.py)

Then you will see the link to run in the browser the game localhost:8000

Now you can zip the folder in the file build/web and upload it in itch.io, using the voice of the menu HTML file.

Tutorial n. 1 to export a python game in the browser

Tutorial n. 2

Or this one

try the game here

https://itch.io/queue/c/2563651/pygame-wasm?position=39


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.