0

I am learning pygame and getting errors.

Whenever I want to put a background image in my window I get an error No file found. While the image name is appropriate.

I'm using Windows PC

Hope this community helps me and motivates me to learn more.

here's my code

import pygame

pygame.init()

window_width = 400
window_height = 400

size = (window_height, window_width)

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Hello_World")

background_image = pygame.image.load("motivation.png").convert()

while True:
        screen.blit(background_image, [0, 0])
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    A good title uniquely describes your specific problem. Everyone asking a question wants help, so "Please Help!" doesn't add anything useful, and since there are _lots_ of questions with the pygame tag, mentioning it in the title doesn't make your question unique either. *"File not found" loading images with correct name* is one example of what a more descriptive title might look like. – Charles Duffy Nov 15 '20 at 17:30

1 Answers1

1

The image file path has to be relative to the current working directory. The working directory is possibly different to the directory of the python file.

See further pygame.image.load('sprite/test_bg.jpg'): pygame.error: Couldn't open sprite/test_bg.jpg.


You have to handle the events in the application loop. See pygame.event.get() respectively pygame.event.pump():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

See further PyGame window not responding after a few seconds

Rabbid76
  • 202,892
  • 27
  • 131
  • 174