0
votes

I am running the following code:

import pygame

pygame.init()

img = pygame.image.load("Picture.jpg")

white = (255, 255, 255)

w = 900

h = 450

screen = pygame.display.set_mode((w, h))

screen.fill((white))


screen.fill((white))

screen.blit(img(0,0))

pygame.display.flip()

while True:

         for event in pygame.event.get():

                if event.type == pygame.QUIT:

                     pygame.quit()

When I run the code the pygame window opens, but it is blank(black) screen. I also get the following error message: Traceback (most recent call last):

File "C:/Users/Draco/OneDrive/Documents/Programming/graphics.py", line 13, in screen.blit(img(0,0)) TypeError: 'pygame.Surface' object is not callable

The image I am trying to open is saved as a JPG file. The image is saved under the name Picture. Many thanks in advance for any help.

1
You probably meant to write screen.blit(img, (0,0)) instead of screen.blit(img(0,0)). - Christian Dean

1 Answers

0
votes

Well, Christian Dean has already answered it. the syntax for pygame.blit() is:

pygame.Surface.blit(source, dest, area=None, special_flags = 0)

where source is a image, dest is the coordinates of the upper left corner of place where the Surface is going to be drawn (or a Rect) and area is a portion of the the Surface you want to draw.

The error you made is that you tried to pass the dest to the image by treating it as a function.

you have to write screen.blit(img, (0, 0)) instead. I recommend you to search the syntax in the pygame website before asking questions.