I want to take a screenshot via a python script and unobtrusively save it.
I'm only interested in the Linux solution, and should support any X based environment.
I want to take a screenshot via a python script and unobtrusively save it.
I'm only interested in the Linux solution, and should support any X based environment.
I have a wrapper project (pyscreenshot) for scrot, imagemagick, pyqt, wx and pygtk. If you have one of them, you can use it. All solutions are included from this discussion.
Install:
Example:
I couldn't take screenshot in Linux with pyscreenshot or scrot because output of
pyscreenshot
was just a black screen png image file.but thank god there was another very easy way for taking screenshot in Linux without installing anything. just put below code in your directory and run with
python demo.py
also there is many available options for
gnome-screenshot --help
This one works on X11, and perhaps on Windows too (someone, please check). Needs PyQt4:
Just for completeness: Xlib - But it's somewhat slow when capturing the whole screen:
One could try to trow some types in the bottleneck-files in PyXlib, and then compile it using Cython. That could increase the speed a bit.
Edit: We can write the core of the function in C, and then use it in python from ctypes, here is something I hacked together:
And then the python-file:
Compile all answers in one class. Outputs PIL image.
Try it: