1

I am making a pygame reaction speed game for a project for computer science in which there is a menu, a maingame and a postgame appraisal with a score and an option to try again. I decided to seperate the three parts of the game into three different python scripts, menu, maingame and postgame. The problem comes when switching between the three scripts, as the intention is to get the code to use the same window and switch seamlessly between, where the actual result is a new window opening. Wondering if anyone has any solutions or a different command to try?

I have used the os.system function in conjunction with the three different python scripts.

Here is an image of the problem, https://i.gyazo.com/ddd4615871b26cf0f34257adb12ce618.png

Here is an example of the menu button which when clicked starts the new script.

'''python def MenuButton(surf, cursor_pos, pressed, rect, color): pygame.draw.rect(surf, color, rect) if rect.collidepoint(cursor_pos) and pressed: os.system("maingame.py") '''

Expected output is the seamless switching of scripts, and the game to stay within one window.

benj
  • 29
  • 3
  • It just doesn't work like this. PyGame is modeled around a single window / full-screen display. You will need to fold your code back into a single executable. If you wish to launch a child-process to calculate something, use the Python subprocess module rather than `system()` and communicate with file handles. https://docs.python.org/3/library/subprocess.html – Kingsley Oct 17 '19 at 22:35

0 Answers0