from PIL import Image, ImageGrab def screenshot(imagefile): ''' Take a screenshot of the entire screen and save it to imagefile ''' image = ImageGrab.grab() return image.save(imagefile) def screenshot_by_size(imagefile,x1,y1,x2,y2): ''' Intercept the screen image within the coordinate range of x1,y1 to x2,y2 and save it to imagefile ''' image = ImageGrab.grab((x1,y1,x2 ,y2)) return image.save(imagefile)