-1

So.THIS:

import pygame
import time
import random
import sys

itworks = True

pygame.init()
screen = pygame.display.set_mode((600, 600))

bootpng = pygame.image.load('bootimage.png')
bootpng = pygame.transform.scale(bootpng, (600, 600))
backgroundmenu = pygame.image.load('Menu_background.png')
backgroundmenu = pygame.transform.scale(backgroundmenu, ((600, 600))
button = pygame.image.load('technical_information_button')
button = pygame.transform.scale(infobut, ((130, 80))
screen.blit(bootpng, (0, 0))
time.sleep(3)

while itworks == True:
    screen.blit(backgroundmenu, (0, 0))
    screen.blit(tekbutton, (470, 520))
    for event in pygame.event.get():
        if ecent.type == pygame.QUIT:
            itworks = False

    #    if event.type == pygame.MOUSEBUTTONDOWN:
    # Set the x, y postions of the mouse click
    #x, y = event.pos
    #if ball.get_rect().collidepoint(x, y):

    pygame.display.flip()

pygame.quit()

is my code. Buuut.. for SOME reason python says "Invalid Syntax" at variable button, line 15*. I really don't know what to do about it, I tried a lot of things, so I hope I can get help from here :D

2 Answers2

2

You need to delete an extra bracket.

Replace: button = pygame.transform.scale(infobut, ((130, 80))

with: button = pygame.transform.scale(infobut, (130, 80))

In Python there should always be an opening bracket and closing bracket.

Edit:

Just to add on, I strongly suggest to replace your while itworks == True into while itworks is True. More information can be seen here: Boolean identity == True vs is True

Basically, that if statement may not give the expected result in some cases due to the equality not comparing references. It is simply the 'pythonic' way of doing things.

RealPawPaw
  • 988
  • 5
  • 9
  • Uhh.. ok I just found out the problem I had that bracket thing and also above it, now it works (well not really it says it can't read the file, but that's something I can fix..) and uhh.. how do you mark answer as accepted? –  Aug 20 '18 at 06:24
0

A little more elaboration.

The problem was that you had the extra parenthesis make in line button = pygame.transform.scale(infobut, ((130, 80)).

The reason you got Syntax Error is python thought you were truing to type variable=(variable_declared="in parenthesis"), which is a Syntax Error.

If you commented all of the code after button = pygame.transform.scale(infobut, ((130, 80)) you get a more explanatory error:

import pygame
import time
import random
import sys

itworks = True

pygame.init()
screen = pygame.display.set_mode((600, 600))

bootpng = pygame.image.load('bootimage.png')
bootpng = pygame.transform.scale(bootpng, (600, 600))
backgroundmenu = pygame.image.load('Menu_background.png')
backgroundmenu = pygame.transform.scale(backgroundmenu, ((600, 600))
##button = pygame.image.load('technical_information_button')
##button = pygame.transform.scale(infobut, ((130, 80))
##screen.blit(bootpng, (0, 0))
##time.sleep(3)
##
##while itworks == True:
##    screen.blit(backgroundmenu, (0, 0))
##    screen.blit(tekbutton, (470, 520))
##    for event in pygame.event.get():
##        if ecent.type == pygame.QUIT:
##            itworks = False
##
##    #    if event.type == pygame.MOUSEBUTTONDOWN:
##    # Set the x, y postions of the mouse click
##    #x, y = event.pos
##    #if ball.get_rect().collidepoint(x, y):
##
##    pygame.display.flip()
##
##pygame.quit()

Now, the code throws the error SyntaxError: unexpected EOF while parsing which is directly caused by the extra parentheses.

That said, I would actually advise you to change while itworks == True: to while itworks: (opposed to @UltraGold's answer).

According to this post and PEP8 (Python's Style Guide) the most 'Pythonic' approach is while itworks versus while itworks == True: and actually further discourages while itworks is True as this is actually a different test that may cause unexpected errors (the problem that @UltraGold was trying to address).

The Matt
  • 1,423
  • 1
  • 12
  • 22