То, что вы хотите сделать, например, как сказал skrx, это цикл while, чтобы непрерывно поддерживать код внутри цикла while
и окно pygame, а также for
Цикл событий, чтобы можно было закрыть окно.Вот как вы можете это сделать:
import pygame
pygame.init()
pygame.display.set_mode((640, 480)) # opens the display
while True: # the while loop that will keep your display up and running!
for event in pygame.event.get(): # the for event loop, keeping track of events,
if event.type == pygame.QUIT: # and in this case, it will be keeping track of pygame.QUIT, which is the X or the top right
pygame.quit() # stops pygame
Есть и другие способы остановить цикл while, и вы можете сделать это:
running = True
while running: # the while loop that will keep your display up and running!
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Надеюсь, это поможет!