3

I saw that post (that is really helpful : Take a screenshot via a python script. [Linux]) about taking a screenshot from python. It works well but I'd like to have the same behavior as gnome-screenshot : having the possibility to choose between :

  • Capturing the whole desktop
  • Capturing an active window
  • Capturing an area

Is there a way to do this in python, or, eventually, to use the gnome-screenshot application to do it, and then getting the file ?

I tried to find the perfect command line for gnome-screenshot to be launched without asking where to save the screenshot after by giving the path at the call, but I can't find it.

Thanks for your help!

jww
  • 97,681
  • 90
  • 411
  • 885
Cyril N.
  • 38,875
  • 36
  • 142
  • 243

2 Answers2

2

I have a wrapper project (pyscreenshot) for scrot, imagemagick, pyqt, wx and pygtk. If you have one of them, you can use it. Capturing an active window is missing.

Install:

easy_install pyscreenshot

Example:

import pyscreenshot as ImageGrab

# fullscreen
im=ImageGrab.grab()
im.show()

# part of the screen
im=ImageGrab.grab(bbox=(10,10,500,500))
im.show()

# to file
ImageGrab.grab_to_file('im.png')
ponty
  • 614
  • 8
  • 8
1

If you are not limited to using using gnome-screenshot specifically, ImageMagick's import command can save directly to file without an interactive prompt.

See here for details: http://www.imagemagick.org/script/import.php

In addition to the command line interface, there is also a Python API.

shang
  • 24,642
  • 3
  • 58
  • 86