Вы делаете pygame.quit()
сразу после pygame.display.set_mode()
. pygame.quit()
завершает работу всех модулей Pygame. Удалите его:
screen = pygame.display.set_mode([500, 500])
pygame.display.set_caption("TicTac")
# pygame.quit() <--- DELETE
pygame.QUIT
не является функцией, это константа перечислителя. Вы не можете вызвать pygame.QUIT
:
if event.type == pygame.QUIT():
if event.type == pygame.QUIT:
Вам нужно только одно приложение l oop, а не 2 из них. Кроме того, вы должны обновить окно либо pygame.display.flip()
, либо pygame.display.update()
import pygame
pygame.init()
screen = pygame.display.set_mode([500, 500])
pygame.display.set_caption("TicTac")
x, y = 250, 250
width, height = 40, 60
vol = 5
run = True
while run:
pygame.time.delay(100)
# handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# clear dispaly
screen.fill((0, 0, 0))
# draw the scene
pygame.draw.rect(screen, (255, 0, 0), (x, y, width, height))
# update display
pygame.display.flip()
pygame.quit()