How can I print the screen in the background with Python

Asked

Viewed 44 times

-1

I would like to be able to make a screenshot of the application running in the background with Python. On each screen the application enters, I need a print. I managed to, with the pyautogui. But, it only takes screenshot of the main screen, when I leave the application running in the background, I only get the screenshots of the screen I’m on and not the application that is running.


nomeArquivo = datetime.datetime.now().strftime('%Y-%M-%d_%H%M%S' + '.png') #nome e formato do arquivo.
foto = pyautogui.screenshot() #foto sendo salva.
foto.save('C:\ProjetosPython\Testes\Evidências/' + nomeArquivo) #caminho onde salvo a foto.```

1 answer

0


in his cron you have to use the export DISPLAY=:0 follows an example:

* * * * * export DISPLAY=:0; /usr/bin/python3 script.py

remembering that the display value has to be the active display. most of the time it is 0. and needs to be run by cron of the user in which the session is started. it cannot be root.

second alternative is to use the scrot

how to install: https://www.tecmint.com/take-screenshots-in-linux-using-scrot/

ex no cron:

* * * * * DISPLAY=:0 /usr/bin/scrot "/home/user/Desktop/screenshots/$(date +'\%d-\%m-\%Y \%T').png"

same thing has q per user cron and not root.

  • Jasar Orion thank you! But, it hasn’t worked yet.

  • strange did the tests here on my pc and function ( I did before posting ). so much so that I have a monitoring system that runs something similar and works

  • I’ll do a little research to see if I can help you better

  • Thank you for your help and attention!

  • there is one thing I forgot: it cannot be in crontab running as root. it has to be in the user where the X session is active. I just hate it here.

  • Thanks, I got.

  • which of the methods you used? mark as solved after

  • I used the second alternative scrot

  • good. how to use Raspberry does not have the scrot for her. hence I have to do in the rsss hand.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.