Code won't work

I’ve been having trouble with all of my code over pygame, and none of them seem to be running properly although I don’t see any problems wrong with the code itself. Can someone please help?

import pygame, sys
from graphics import *
from pygame.locals import *

# create the screen
pygame.init()
screen = pygame.display.set_mode((800,600))

screen.fill((255,255,255))

white = (255, 255, 255)
black = (0, 0, 0)
blue = (0, 0, 255)
red = (255, 0, 0)
green = (0, 128, 0)

pygame.draw.rect (screen, green, (10, 10, 50, 50), 3)
pygame.draw.rect (screen, red, (50, 100, 80, 60), 7)
pygame.draw.rect (screen, blue, (350, 300, 100, 50), 5)
pygame.draw.rect (screen, black, (250, 200, 50, 100), 4)

pygame.display.update()

while (True):
 for event in pygame.event.get():
     if (event.type==pygame.QUIT or (event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE)):
         pygame.quit()
         sys.exit();
1 Like

Sorry, didn’t realize that the code wouldn’t indent, here’s the link: https://replit.com/@AngelinaLu2/python01#pygameBasics01.py

1 Like

Have you tried copying the code from smileyface to main.py instead of using from smileyface import *? Or you could configure the Repl to run smileyface instead:

Just click the next to “Files” then click “Show hidden files”. Next click on the .replit file and finally you can change the entrypoint to whatever file you want to run.

Images

Dots

Show hidden files

edited

You can also see the docs on how to configure a Repl: https://docs.replit.com/programming-ide/configuring-repl

2 Likes

Does the console show any error messages?
In smileyface.py, you reference some variables that do not exist.

2 Likes