(The post title said 'in the Jupyter Notebook Demo' and so this at first addresses that with the most online Jupyter-associated offering; however, it may be possible with pygame-ce and GitHub pages/static hosting and accommodating javascript code sopyodide served other ways, see last sectionoptions #2a & 2b below.)
Alternative #2#2a possibility with JavascriptPyodide/Javascript using pyodide and static hosting(?) Py.Cafe:
(Pyodide is the kernel being used in JupyterLite, but you may be able to use Pyodide in a browser to run pygame-ce(?)Pygame. This details the best lead I have found so far to do that.)
In a flash of inspiration, I remembered py.cafe also uses pyodide and has amazing offerings that wouldn't have been possible a few years ago.
I searched 'py.cafe pygame' and found this amazing example offered by Maarten Breddels:
This is probably more close to what you were originally trying with your offered code bock as it is indeed Python code; however, again you'll see it needs a lot of very particular special handling to get it working there that your code wasn't close to doing.
You'll see by reading the page here in it's entirety, even way down at the bottom Py.cafe offers various frameworks with Jupyter-related potentially being one because under 'Vote for the next', there are currently three Jupyter-related offerings as options. But this again makes it clear that the pygame with pyodide would be separate, or more easily separate, from JupyterLite at this time.
I'll point out that Pygame seems have been developed in the last few years to look and see if in pyodide-based environment, see sys.platform == 'emscripten' used in github.com/pygame-web/archives/blob/… . And see Pyodide FAQ:'How to detect that code is run with Pyodide?'. And so it being possible with Pyodide makes sense, it's just not the classic way.
Alternative #2b possibility with Javascript/Pyodide using pyodide and static hosting(?):
(Pyodide is the kernel being used in JupyterLite but you may be able to use Pyodide with javascript a browser to run pygame-ce(?).)
Also, I had seen that with pyodide you may be able to use pygame in a browser directly from a server without JupyterLite involved? There was a StackOverflow post that got closed but I recorded the example at github.com/IEYT/Mayor-Rush/blob/… . Note it says 'Thanks to Furas for helping me import pygame successfully.' here. The deleted post is at https://stackoverflow.com/questions/79593483/how-to-use-pygame-ce-in-pyscript#comment140382075_79593483 .
Pygame seems have been developed in the last few years to look and see if in pyodide-based environment, see sys.platform == 'emscripten' used in github.com/pygame-web/archives/blob/… . And see Pyodide FAQ:'How to detect that code is run with Pyodide?'. So as I said under option #2a, it make sense there's other routes , but it's definitely not the classic way though to use Pygame.