[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] how to show my pic on screen ?



black wrote:
> I've already build up a surface but dunno how to display it. my code is
> below:
> 
> import pygame
> 
> pic1=pygame.image.load("C:\Documents and Settings\wd09\My Documents\My
> Pictures\dog.jpg")

looks like jesse already sent you a good reply. it sounds like you really
are starting at the beginning. i'll show you a complete program below that
would show an image. you'll definitely want to start with some of the
pygame tutorials and examples.

in pygame you can have many many images loaded, but you can only see what
is drawn on the "display surface". if you think about a normal game, this
makes a lot of sense. a game will have many images, but you'll only see a
few of them on the screen at any time. in pygame, the images are called
"Surface objects", each surface is an image. when you load an image, it
creates a new Surface for you with the image on it. to see the image, you
will need to draw the image onto the display Surface. in pygame, you "blit"
surfaces from one to another to draw them. a 'blit' is a fancy way of
copying from one image to another, since it handles many special things
like clipping and transparancy. when you draw on the pygame display
surface, the changes are not immediately visible, you need to update the
display to commit what is drawn to the screen.

here is a program that does everything explained




#initialize
import pygame
file = "C:\Documents and Settings\wd09\My Documents\My Pictures\dog.jpg"

#load the image
image = pygame.image.load(file)

#create a window on the screen
size = image.get_size()
window = pygame.display.set_mode(size)

#draw the image on the screen and update
window.blit(image, (0, 0))
pygame.display.update()

#wait for the user to press a key or quit
while 1: #wait forever
    event = pyame.event.wait()
    if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
        break



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org