Anyone know why this doesn't work. I'm new to coding.

Joined
Jan 20, 2021
Messages
1
Reaction score
0
import pygame
import os

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Aberoth")

Black = (150, 150, 150)
White = (255, 255, 255)
FPS = 100
clock = pygame.time.Clock()

CircleX = 100
CircleX = 10 + CircleX
CircleY = 200
circle_img = pygame.image.load(os.path.join('games', 'circle.png'))

def circle(x, y):
WIN.blit(circle_img, (x, y))

def draw_window():

WIN.fill(White)
circle(CircleX, CircleY)
pygame.display.update()



def main():
clock.tick(FPS)

run = True
while run:

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_window()

pygame.quit()
quit()


if __name__ == "__main__":
main()
 
Joined
Feb 8, 2021
Messages
8
Reaction score
2
You are getting to pygame.quit() before you want to. Try it like this :

Python:
import pygame
import os

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Aberoth")

Black = (150, 150, 150)
White = (255, 255, 255)
FPS = 100
clock = pygame.time.Clock()

CircleX = 100
CircleY = 200
circle_img = pygame.image.load(os.path.join('games', 'circle.png'))

def circle(x, y):
    WIN.blit(circle_img, (x, y))

def draw_window():
    WIN.fill(White)
    circle(CircleX, CircleY)
    pygame.display.update()

def main():
    clock.tick(FPS)
    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
        draw_window()

if __name__ == "__main__":
    main()
    pygame.quit ()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top