954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how do I display an image

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

wolfeater017
Light Poster
35 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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())

redyugi
Junior Poster in Training
80 posts since Jul 2009
Reputation Points: 15
Solved Threads: 30
 

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

wolfeater017
Light Poster
35 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

I guess it is

windowSurface.blit(pi, 25, 25)

or

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


but i never used pygame.

Beat_Slayer
Posting Pro in Training
405 posts since Jun 2010
Reputation Points: 30
Solved Threads: 105
 

It's the second one

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


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

wolfeater017
Light Poster
35 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

There is a slightly more advanced example here:
http://www.daniweb.com/forums/post1282201.html#post1282201

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: