Python PIL | ImageGrab.grab () method

Python Methods and Functions

The PIL.ImageGrab.grab () method takes a screenshot. Pixels inside the bounding box are returned as "RGB" on Windows or "RGBA" on macOS. If there is no bounding box, the entire screen is copied.

  Syntax:  PIL.ImageGrab.garb (bbox = None)  parameters:   bbox:  What region to copy. Default is the entire screen.  Returns:  An image 

# Import Image and ImageGrab module from PIL

from PIL import Image, ImageGrab

 
# create an image object

im1 = Image. open (r "C: Userssadow984Desktopdownload2.JPG" )

 
# using the capture method

im2 = ImageGrab.grab (bbox = None )

 
im2.show ()

Output:

# Import Image and ImageGrab module from PIL

from PIL import Image, ImageGrab

 
# create image object

im1 = Image. open (r "C: Userssadow984Desktopdownload2.JPG" )

 
# using the capture method

im2 = ImageGrab.grab (bbox = ( 0 , 0 , 300 , 300 ))

 
im2.show ()

Output:

For different different bbox values ​​can be used for screen sizes.