import pygame import subprocess def main(): # Initialize Pygame pygame.init() screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # Set to full screen pygame.display.set_caption("Auto Reopen Pygame") # Hide the mouse cursor pygame.mouse.set_visible(False) # Set mouse cursor position to the middle of the screen pygame.mouse.set_pos(screen.get_width() // 2, screen.get_height() // 2) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit() # Reopen the script using subprocess subprocess.Popen(['python', __file__]) if __name__ == "__main__": main()