0

Computing project. I'm making a menu for a Math game and encountered a strange error. FYI I took most of this code off pygame.org. I get an invalid syntax error on my colon at:
if name == 'main': main()

Why am I getting this error and how to fix it. I have never really coded before so assume my ignorance and don't be mean please.

Thank you very much :)

import pygame

nicegreen =  (50, 200, 90)
black = (0, 0, 0)

def button (message, x, y, width, height, initialc, hoverc, action=None ):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

def main():
    pygame.init()
    screen = pygame.display.set_mode((640, 480))
    pygame.display.set_caption('Math Game Project')

    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((50, 200, 90))

    font = pygame.font.Font(None, 36)
    text = font.render("Math Quest", 1, (120, 10, 10))
    textpos = text.get_rect()
    textpos.centerx = background.get_rect().centerx
    background.blit(text, textpos)
    # Blit everything to the screen
    screen.blit(background, (0, 0))
    pygame.display.flip()

    # Event loop
    while 1:
        for event in pygame.event.get():
            if event.type == QUIT:
                return

            startbutton(

        screen.blit(background, (0, 0))

if __name__ == '__main__': main()
Thomas Fritsch
  • 8,893
  • 33
  • 34
  • 46
  • 1
    This is code is incomplete. It is missing a closing parenthesis somehwere, probably after `screen.blit`. Add one, the syntax error will go away but I don't know if the program is correct. – giusti Feb 17 '18 at 16:23
  • 1
    Also, you cannot write `if event.type == QUIT:` when you are doing `import pygame`. The line should be `if event.type == pygame.QUIT:`. – Micheal O'Dwyer Feb 17 '18 at 17:21
  • `startbutton(` should be `startbutton(parameters)` – gnawydna Feb 18 '18 at 05:04

0 Answers0