is it possible to run pygame or pyglet in a browser?

柔情痞子 提交于 2019-11-27 15:08:06

Neither pyglet nor pygame will run in a browser. I wouldn't really recommend using Python at all if you target is a web browser. JavaScript (with HTML5 Canvas), Flash, or Java applets are better suited for that environment.

If you're dedicated to the idea of using Python, there are a number of projects that can compile Python into JavaScript. There are some mentioned on the Python wiki. Here are a few:

You'll need to write your own graphics and audio systems, though, since none of those projects can convert the native code needed by pyglet and pygame into JavaScript.

It requires a bit of reprogramming, but i made a pygame library "port" to the browser/nodewebkit using Brython and GameJS. You can program using a version of pygame and python 3 in the browser. You can check it out at https://github.com/asherwunk/pygjs

Repl.it -- an online IDE -- just announced Pygame and any other Python GUI or game library. You can start here.

Here are some examples:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!