0
votes
bif="bg.jpeg"

mif="ball.png"

import pygame

import sys

from pygame.locals import *

pygame.init()

screen_size=(640, 360)

screen=pygame.display.set_mode( screen_size, 0, 32)

background=pygame.image.load(bif).convert()

mouse_c=pygame.image.load(bif).convert_alpha()



while (True):

    for event in pygame.event.get():

        if event.type == QUIT:

            pygame.quit()

            sys.exit()

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

    x,y = pygame.mouse.get_pos()

    x -=mouse_c.get_width()/2

    y -=mouse_c.get_height()/2

    screeb.blit(mouse_c, (x,y) )

    pygame.display.update()

Traceback (most recent call last):

File "C:\Users\Ofek\Desktop\game\try.py", line 12, in

background=pygame.image.load(bif).convert()

pygame.error: Couldn't open C:\Users\Ofek\Desktop\game\bg.jpeg

1
make sure your image is in the same directory. make sure your path is correct. - ecline6
It is in the same dir.. - user2410243
You're certain? Make super sure of it, and make sure it's named correctly. You can try using an absolute path. bif = "C:\\Users\\Ofek\\Desktop\\game\\bg.jpeg" - ecline6

1 Answers

0
votes

I think I have found the issue your having, first I created two images in paint for bg and ball then ran the code you've provided which returned:

Traceback (most recent call last):
  File ".\pypic.py", line 17, in <module>
    background=pygame.image.load(bif).convert()
pygame.error: Couldn't open bg.jpeg

To which I thought there might be an issue with the current working directory so I tried using the os.getcwd() + "\\" + bg this resulted in the same error. So the only thing I can think that your having an issue with is the line:

bif="bg.jpeg"

which I now believe should read:

bif="bg.jpg"

As below:

import pygame
import sys
from pygame.locals import *

# Image variables
bif="bg.jpg"  # Have changed this from .jpeg to .jpg
mif="ball.png"

pygame.init()
screen_size = (640, 360)
screen=pygame.display.set_mode( screen_size, 0, 32)
background = pygame.image.load(bif).convert()
mouse_c = pygame.image.load(bif).convert_alpha()

while (True):
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    screen.blit(background, (0,0) )
    x,y = pygame.mouse.get_pos()
    x -= mouse_c.get_width() / 2
    y -= mouse_c.get_height() / 2
    screen.blit(mouse_c, (x, y))  # Had to change this because it said screeb!
    pygame.display.update()

Have a try of that change and see if it works! If not post the error you get as a comment and we can try to fix it.