почему окно моментально закрывается? (pygame)
import pygame
scr = pygame.display.set_mode((500, 500))
scr.fill('green')
pygame.init()
f1 = pygame.font.Font(None, 50)
text = f1.render(
'there is nothing', True, (255, 215, 0)
)
scr.blit(text, (150, 300))
rect = pygame.Rect(150, 50, 200, 80)
pygame.draw.rect(scr, 'red', rect=rect)
Ответы (2 шт):
Автор решения: Aleksandr Fetisov
→ Ссылка
Нужно создать бесконечный цикл чтоб окно не закрывалось
import pygame
pygame.init()
scr = pygame.display.set_mode((500, 500))
scr.fill('green')
f1 = pygame.font.Font(None, 50)
text = f1.render(
'there is nothing', True, (255, 215, 0)
)
scr.blit(text, (150, 300))
rect = pygame.Rect(150, 50, 200, 80)
pygame.draw.rect(scr, 'red', rect=rect)
# основной цикл событий
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
Автор решения: Danis
→ Ссылка
Код дошёл до конца и просто закрылся. Надо добавить бесконечный цикл в конец:
running = True
while running:
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
running = False