I am using pyautogui to take screenshots of a certain area of the screen. In an attempt to see what is going on with my script that I need to change, I want to save each screenshot into a folder. My thought was to throw a counter on and add it to the screenshot name.
The normal code for a screenshot is:
pyautogui.screenshot('opponent.png', region=(177, 743, 635, 135))
Instead of using the name opponent
I would want the name to be opponent + a .png
. I would use a = a + 1
inside the loop to change a
each time, I am just not sure the proper way to add the variable a
.
Example of the file names would be:
opponent1.png
opponent2.png
opponent3.png
opponent4.png
...
Edit: Based off the Question that this was listed a possible duplicate of I tried this code:
pyautogui.screenshot('opponent%d.png', region=(177, 743, 635, 135)) % won
where won is a variable counting which opponent the screenshot is of. The error I get is:
TypeError: unsupported operand type(s) for %: 'Image' and 'int'
I also tried using the format solution and used this line of code:
pyautogui.screenshot('opponent{0}.png', region=(177, 743, 635, 135)).format(won)
This also through a TypeError: 'NoneType' object is not callable