Can someone tell me how to display an image with pygame. By the way I am using python 3.x.

Recommended Answers

All 5 Replies

I thought pygame didn't work with 3.X?
If it does, it should still follow the same instructions.
1) Load image (pygame.image.load(image))
2) Blit onto display screen (screen_variable.blit(image, image.coordinates))
3) Update display (pygame.display.update())

sorry 3.0
but when I do this

import pygame, sys, time, random
from pygame.locals import *

# set up pygame
pygame.init()
mainClock = pygame.time.Clock()

# set up the window
WINDOWWIDTH = 400
WINDOWHEIGHT = 400
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Sprites and Sound')
# set up the colors
BLACK = (0, 0, 0)

# set up the block data structure
pi = pygame.image.load('C:/python31/include/player.ss.png')

windowSurface(pi.blit(pi,20,20))
pygame.display.update()

it keeps giving this back

Traceback (most recent call last):
  File "C:/Python31/7.py", line 19, in <module>
    windowSurface(pi.blit(pi,25,25))
TypeError: invalid destination position for blit

I don't understand why it isn't recognizing any of the coordinates I try

I guess it is

windowSurface.blit(pi, 25, 25)

or

windowSurface.blit(pi, (25, 25))

but i never used pygame.

It's the second one

windowSurface.blit(pi,(50,100))

thanks for someone who dosen't use pygame your pretty good with it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.