I'm trying to write a python script in ubuntu 16.04 LTS, that grabs a currently open terminal and take a screen-shot of it.
Most of the already available solutions (For eg. here) simply captures the screen-shot of the entire screen.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityI'm trying to write a python script in ubuntu 16.04 LTS, that grabs a currently open terminal and take a screen-shot of it.
Most of the already available solutions (For eg. here) simply captures the screen-shot of the entire screen.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gdk
# full screenshot
window = Gdk.get_default_root_window()
pb = Gdk.pixbuf_get_from_window(window, *window.get_geometry())
pb.savev("full.png", "png", (), ())
# screenshots for all windows
window = Gdk.get_default_root_window()
screen = window.get_screen()
typ = window.get_type_hint()
for i, w in enumerate(screen.get_window_stack()):
pb = Gdk.pixbuf_get_from_window(w, *w.get_geometry())
pb.savev("{}.png".format(i), "png", (), ())
# screenshot active window
screen = Gdk.get_default_root_window().get_screen()
w = screen.get_active_window()
pb = Gdk.pixbuf_get_from_window(w, *w.get_geometry())
pb.savev("active.png", "png", (), ())