0

I want the code to work. So that I can get a good grade of it. I have tried a lot of things so that the code can work event.

import pygame.sys
from pygame.locals import *

pygame.init()

DISPLAY=pygame.display.set_mode((500,400),0,32)
pygame.disply .set_caption(AMBERMIR)

WHITE=(255,255,255)
BLUE=(0,0,255)

DISPLAY.fill(WHITE)

pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50))

if event.type == QUIT:
    pygame.quit()
    sys.exit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Amber Mir
  • 11
  • 3

1 Answers1

0

You've to implement a main loop which is continuously running. Inside the main loop, an event loop can be handle the events.
Use pygame.event.get() to get and remove all pending events from the loop. The return value of pygame.event.get() is a list of pygame.event.Event objects.
After drawing the scene, the window has to be updated by either pygame.display.update() or pygame.display.flip():

import sys
import pygame
from pygame.locals import *

pygame.init()

AMBERMIR = "my window"
DISPLAY=pygame.display.set_mode((500,400),0,32)
pygame.display.set_caption(AMBERMIR)

WHITE=(255,255,255)
BLUE=(0,0,255)

# main loop
run = True
while run:

    # event loop
    for event in pygame.event.get():
        if event.type == QUIT:
            run = False # terminate main loop on QUIT

    # clear display 
    DISPLAY.fill(WHITE)

    # draw rectangle
    pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50))

    # update display
    pygame.display.update()

pygame.quit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174