I am having difficulties setting a background image for my Pygame window. I’ve looked for other sources, but it seems I cannot find anything helpful or useful.
I am currently aiming to make a 2D Platformer, but I want to start with the background first.
Here is my code:
import pygame, sys
from pygame.locals import QUIT
pygame.init()
DISPLAYSURF = pygame.display.set_mode((500, 500))
#background
background = pygame.load.image("GRID.jpg")
background = pygame.transform.scale("GRID.jpg",(500,500))
# caption and icon
pygame.display.set_caption('pallor TEST')
icon = pygame.image.load("char.png")
pygame.display.set_icon(icon)
# Displays it?
pygame.display.flip()
runing = True
while runing:
DISPLAYSURF.blit("GRID.jpg",(0,0))
for event in pygame.event.get():
if event.type == QUIT:
runing = False
pygame.display.update()
pygame.quit()
I keep getting:
Could someone please help me?
I don’t know what is wrong.
The first argument for pygame.transform.scale should be a pygame.Surface, not a string.
The function you used earlier, pygame.load.image, returns a pygame.Surface instance, hence you can rewrite your code like this:
It seems to work in terms of the area, but I still seem to have an issue in displaying it.
Do I need to change the function, or did I typo something?
Or do I need to set the image into a folder and use it as a path?
I really recommend looking at the docs in the future, it will tell you exactly what type goes there. It will tell you it takes surface instead of string. And even if it did take string, it would be a waste to load it every time.