'pyautogui screenshot changes everytime I use it

I have this code:

import os 
import cv2  
import numpy as np 
import pyautogui    
screenshot = pyautogui.screenshot('myscreenshot.png',region=(71,144,800,464)) 

The program saves the screenshot in my files as myscreenshot.png the first time it runs and the picture is exactly what I want.

The second time when I run the program, it saves the picture as myscreenshot000.png and modifies the original myscreenshot.png as if it was taking a picture of the original lower right corner, but crops it up and I lose a little of the image every time I run the code.

So by the time I take a fourth screenshot, the orginal is completely black.

I have a feeling it has to do with my Image Viewer in windows because when I look at the original in Image viewer. It has a black contour and the black contour just gets bigger at every run.

I need to know how to prevent that, because I use this code in a loop in another program and than it gives me an error Does anyone know how to prevent that?

NB: The three last pictures here are to show you how they are saved on my computer, it shows in the right window.

EDIT: The docstring didn't change anything to the problem and i Have to add that, on the second, third and fourth run of the program, pyautogui doesn't take a screenshot of the screen, it just modifies the original image, because if i say put a window of youtube on the region pyautogui captures, it doesn't appear in the original image('myscreenshot.png'), it only appears on the new files saved ('myscreenshot_00X.png')

This is the originial 1rst 'myscreenshot.png'

This is 'myscreenshot.png' on the second run

This is 'myscreenshot.png' on the third run

This is 'myscreenshot_000.png that appears on the second run

This is 'myscreenshot_001.png' that appears on the third run

This is 'myscreenshot_002.png' that appears on the fourth run



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source