I'm trying to create a website for a university project where you can play some minigames I've programmed with Pygame (Python). How can I make the games executable online (like flashgames)? I'm using php
Asked
Active
Viewed 1.6k times
5
-
3Hi! Welcome to StackOverflow! I would suggest you to be more specific in what you need, and also to post whatever attempt you have for what you are trying to achieve. See also [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – norok2 Oct 01 '18 at 10:13
-
You can’t. There is (unfortunately) no way to run Python with pygame as a web application. – deets Oct 02 '18 at 22:14
-
I'm also finding a way to realize it, but I only find a good way by web socket.But I think it's will make a delay problem. Skuplt maybe a good way to realize by js. I'm looking for another way. – DustyPosa Apr 01 '19 at 03:05
4 Answers
8
Now you can run pygame in browsers: Just found this. Great news for teachers.

Jeremy Chen
- 1,299
- 2
- 11
- 18
-
I used trinket with my students. It doesn't properly play sound files, but is a cool way to get your games online with relative ease. Here is an example of mine running on trinket. [My Game](https://sciencelee.trinket.io/sites/sciencelee-blasteroids). Few tips: limit your screen size to 800x600. Make a no-sound version of your game first so it is easier to troubleshoot when you add sound (use ogg). I also had problems with custom fonts. – ALee Jun 07 '21 at 18:42
0
If you're not fully committed to pygame, you could investigate the pyjsdl project which is modelled on pygame. You'd still have to translate your code.
Another alternative is to create stand-alone executable of your existing pygame projects using pyinstaller and distribute those.
Kivy can generate HTML5 apps, e.g. here's a tutorial on creating pong. It's not really directed at games.
Or you could consider redeveloping using a web game library in a different language (probably javascript).

import random
- 3,054
- 1
- 17
- 22
-
do you know which one of the above methods is better for collecting user data? – jigz Jan 27 '23 at 00:11
-
@jigz it depends on what sort of data you want to gather, the users click-speed, their browser footprint? I think you'd be better off with a framework designed for web. – import random Jan 27 '23 at 01:03
-
I just need to record their input. For instance, consider their are playing a grid-world game with keyboard (i.e., changing the state of their agent). I want to save the game data so I can replay later. Does this make sense? – jigz Jan 27 '23 at 01:56
-
If you're already handling events @jigz, then you can extend the existing handler to log the actions for replay etc. – import random Jan 27 '23 at 03:08
0
PYGAME ON WEB(Pygbag)
Now you can run pygame in browser using the pygbag,for more details you can checkout :
For more information you can checkout
- The
pygame-ce
discord.(pygame-community discord)

cool-guy
- 3
- 1
-1
I have tried several options.
- Trinket.io didn't work well to me since it is cropping the game screen.
- itch.io requires a downloadable file which I didn't have
- I tried to use http://www.skulpt.org/, but it didn't even open.
- So I ended up using replit.com, since this was the only site that didn't crop the game and could host pygame app in browser

Patlatus
- 1,217
- 2
- 16
- 28