Pygame would be the perfect use case for this. It also supports running in the browser via https://pypi.org/project/pygbag/