Friday, September 5, 2025
HomeLanguagesPygame – surface.blit() function

Pygame – surface.blit() function

surface.blit() function draws a source Surface onto this Surface. The draw can be positioned with the dest argument. The dest argument can either be a pair of coordinates representing the position of the upper left corner of the blit or a Rect, where the upper left corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not affect the blit.

Syntax : blit(source, dest, area=None, special_flags=0) -> Rect

Parameters:

  • Source – Draws a source Surface onto this Surface
  • dest – The draw can be positioned with the dest argument.
  • area -A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit

Python3




# import pygame module
import  pygame
  
pygame.init()
  
# width
width = 680
  
# height
height = 480
  
#store he screen size
z = [width,height]
  
# store the color
white = (255, 255, 255)
screen_display = pygame.display
  
# Set caption of screen
screen_display.set_caption('GEEKSFORGEEKS')
  
# setting the size of the window
surface = screen_display.set_mode(z)
  
# set the image which to be displayed on screen
python = pygame.image.load('bg.jpg')
  
# set window true
window = True
while window:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            window = False
              
            # display white on screen other than image
    surface.fill(white)
      
# draw on image onto another
    surface.blit(python,(50, 50))
    screen_display.update()
  
pygame.quit()


Output:

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS