Thursday, September 4, 2025
HomeLanguagesPython PIL | ImageGrab.grab() method

Python PIL | ImageGrab.grab() method

PIL is the Python Imaging Library which provides the python interpreter with image editing 
capabilities. The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory.
PIL.ImageGrab.grab() method takes a snapshot of the screen. The pixels inside the bounding box are returned as an “RGB” image on Windows or “RGBA” on macOS. If the bounding box is omitted, the entire screen is copied.
 

Syntax: PIL.ImageGrab.grab(bbox=None)

parameters: 
bbox: What region to copy. Default is the entire screen.

Returns: An image

 

Python3




# Importing Image and ImageGrab module from PIL package 
from PIL import Image, ImageGrab
    
# creating an image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
    
# using the grab method
im2 = ImageGrab.grab(bbox = None)
    
im2.show()


Output: 
 

 

Python3




# Importing Image and ImageGrab module from PIL package 
from PIL import Image, ImageGrab
    
# creating an image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
    
# using the grab method
im2 = ImageGrab.grab(bbox =(0, 0, 300, 300))
    
im2.show()


Output: 
 

Different values of bbox can be used for different screen sizes.
 

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS