python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

Is it possible to run pygame using python-shell?

Open willfranklyn opened this issue 4 years ago • 3 comments

I am working on a project to create a working python terminal in the browser and love this node python solution.

Is there anyway to import and run pygame using python-shell? I'm not sure how the window would appear on the front end.

Here is the code I currently have:

const shell = new PythonShell('script.py', { mode: 'text', pythonOptions: ['-u'] }); shell.on('message', line => { console.log('line: ', line); }) .on('error', err => { console.log(err); }) .on('close', () => { console.log('Finished'); }); setTimeout(() => { shell.send(4); }, 1000);

script.py: import pygame pygame.init() screen = pygame.display.set_mode((500, 500)) done = False x=60 y=60 while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True pygame.draw.rect(screen, (0,128,255), pygame.Rect(x, y, 90, 90)) pygame.display.flip()

willfranklyn avatar Jun 22 '21 17:06 willfranklyn

Would be curious to know more about this too!

code-leen avatar Jun 23 '21 03:06 code-leen

I don't see a reason why it should not work. I have tried using several other modules earlier and they worked smoothly. You should have the pyGame module installed using pip into your desktop.

You can also refer to a similar issue in case you run into any problems. [https://github.com//issues/187]

nixxby avatar Feb 02 '22 14:02 nixxby

hey,can anyone help with Pygame,its shows an error when writing the pygame.init()

LevancoMunnick avatar Nov 06 '22 00:11 LevancoMunnick