-1

I have a python file that I use pygame in, I want to press a key to open another pygame file and have both of them still open.

The first file is named editor and the other game.

For this in editor.py i'm importing game.py to open it but when the game.py is opened the editor.py closes, and I want both to remain open, is there a way to do it?

editor.py

import pygame
import keyboard

pygame.init()
screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE)
pygame.display.set_caption("Editor")
game_launched = False

while True:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
    
    # Launch the game file
    if keyboard.is_pressed("p") and game_launched == False:
        game_launched = True
        import game

game.py

import pygame

pygame.init()
screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE)
pygame.display.set_caption("Game")

while True:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

0 Answers0