2

I've got this code:

import pygame, sys
from pygame.locals import *

pygame.init()

WHITE = (255,255,255)

class setup():
    def set_resolution(x, y):
        global surf
        global screen
        surf = pygame.Surface((x,y))
        screen = pygame.display.set_mode((x,y))
        pygame.display.set_caption("Lewis' Game")
        pygame.draw.rect(screen, WHITE,(200,150,150,50))

    def menu():
        pass

setup.set_resolution(1024,768)
setup.menu()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()

For some reason, the pygame.draw.rect(screen, WHITE,(200,150,150,50)) at the end of the setup function doesn't actually appear unless I show the desktop and them tab back in. I'm not sure why this is happening as it's never happened before. I should mention that I'm still learning pygame, and this code is just for practice.

Many thanks in advance.

Lewis
  • 317
  • 3
  • 12

1 Answers1

3

change your while loop to include this:

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
    pygame.display.flip()    # pygame.display.update works as well

if you want more on the difference of these, see Difference between pygame.display.update and pygame.display.flip

Michael
  • 436
  • 3
  • 11