Skip to content
← Back to Community
help with drawing images in pygame
Profile icon
Trex10

Hello,
I'm having trouble making images in pygame, I define the image fine, but its the screen.blit where I get stuck. I've seen some answers, but which would be the simplest for me to use in the future?

P.S. Sorry if I don't explain this well

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
Trex10
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Solution

after you import pygame, you need to add pygame.init() Then blit it. like this.

import pygame pygame.init() display_width = 800 display_height = 600 gameDisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('something') Img = pygame.image.load('something.png') gameDisplay.blit(Img, (x,y))

look here for more info.

https://pythonprogramming.net/displaying-images-pygame/

That should work

Profile icon
Trex10

@RYANTADIPARTHI
It says that "gameDisplay is not defined"

Profile icon
RYANTADIPARTHI

@Trex10 did you follow my exact code?

if that doesn't work, then try going to the link.

Profile icon
Trex10

@RYANTADIPARTHI
Ok now it isn't giving me any errors. But it just gives me a white/gray screen with no image

Profile icon
RYANTADIPARTHI

@Trex10 ok, do you have the correct image file?

Profile icon
Trex10

@Trex10
and a bunch of ALSA lib thingies

Profile icon
Trex10

@RYANTADIPARTHI
I think so, I put the image in a repl.it file and said image = pygame.image.load("image.png") and the file name is image.png

Profile icon
RYANTADIPARTHI

@Trex10 ok, i got it. It's showing white, because your image is white. It's working, but your image is white, and the only text in the white image is hard to see.

Profile icon
Trex10

@RYANTADIPARTHI
ok, I added a ton of red in the pic and its still only white, I gtg now so ig I'll look more into this later

Profile icon
RYANTADIPARTHI

@Trex10 the image still says it's the white.

Profile icon
Trex10

@RYANTADIPARTHI
I changed the entire image to lime green, its still just white

Profile icon
plscodeinjava

nOooOb

Profile icon
Trex10