so i've changed the window color to a white color, unfortunately its not updating, it also returns an error
code:
import pygame
WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display = pygame.display.set_caption('PyGame Test')
WHITE = (255,255,255)
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
WIN.fill(WHITE)
pygame.display.update()
pygame.quit()
if __name__ == '__main__':
main()
what am i doing wrong?
CodePudding user response:
I believe you need to initialize the display module. Try pygame.init()
http://www.pygame.org/docs/ref/display.html#pygame.display.init
CodePudding user response:
In order to set the caption of the window, you need to type pygame.display.set_caption("Caption"). In your code, I see that you typed pygame.display = pygame.display.set_caption('PyGame Test'), which results in an AttributeError because pygame.display.set_caption() returns None, meaning you set pygame.display to None. So if you replace that line with pygame.display.set_caption('PyGame Test'), it will work.
Full code:
import pygame
WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('PyGame Test')
WHITE = (255, 255, 255)
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
WIN.fill(WHITE)
pygame.display.update()
pygame.quit()
if __name__ == '__main__':
main()
For more info, check this page
