Answers for "how to show an image in pygame"

3

load images pygame

import pygame
from pygame.locals import*
img = pygame.image.load('clouds.bmp')

white = (255, 64, 64)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
screen.fill((white))
running = 1

while running:
    screen.fill((white))
    screen.blit(img,(0,0))
    pygame.display.flip()
Posted by: Guest on December-04-2020
2

draw image pygame

import pygame as pg

pg.init()

screen = pg.display.set_mode((display_width,display_height))

# load the image in with file name
yourImg = pg.image.load('yourImg.png')
def showImg(x,y):
  	# pass the image and x,y values to screen
    screen.blit(yourImg, (x,y))
    
done = False
while not done:
  	for event in pg.event.get():
      if event.type == pg.QUIT:
        pg.quit()
        quit()
    # call the function
	showImg(10,10)
    pg.display.update()
pg.quit()
quit()
Posted by: Guest on November-27-2020
1

how to blit image in pygame

def blit_img(img,x,y):
	screen.blit(img,[x,y])
Posted by: Guest on November-15-2020

Code answers related to "how to show an image in pygame"

Python Answers by Framework

Browse Popular Code Answers by Language