0
Hello! My problem is this: I want to make a screenshot of my pc screen using python, I can even beat the screenshot, however, the screenshot is only saved after running the program, I say, the print is only saved after my code finishes running... Is there any way to save the screenshot while running the program? Follows the code:
import pyautogui
import time
capturar = pyautogui.screenshot()
capturar.save('foto.jpg')
for a in range(1,10):
print(a)
time.sleep(1)
As I said, screen capture is only saved after the for
, that is when the code stops running. It can be saved before the execution of the program?
The problem still persists... It saves the image only at the end of code execution, I would like it saved during execution.
– user218366
It would be an image sequence ?
– stack.cardoso
What do you mean image sequence? Do you mean multiple photos? If that’s what you mean, I should say I just want to take a screenshot and save it, but before the program stops running
– user218366
@Rcoletto, how are you testing whether the photo exists or not? I modified the post showing that saved before the loop.
– Paulo Marques
I ran the code you sent, apparently it works, but the photo only appears in my files when it stops running.
– user218366
The
os.path.isfile(foto)
test if the file is on your operating system... See that it is! As you are testing "only appears in my files"?– Paulo Marques
Thanks for the help! I had to restart the pc, and after it did that I tested the code again and it worked! I don’t know exactly what happened, but it worked! Thank you.
– user218366
@Rcoletto I’m glad it’s working... If you think it’s relevant, give a read here
– Paulo Marques