I've spend past 3 days searching in google, how can I create a screenshot with PyGTK+3 ? There are gallizion tutorials about pyqt,pygtk+2,wx and PIL.
By the way, I don't need external programs like scrot, imlib2, imagemagick and so on.
I've spend past 3 days searching in google, how can I create a screenshot with PyGTK+3 ? There are gallizion tutorials about pyqt,pygtk+2,wx and PIL.
By the way, I don't need external programs like scrot, imlib2, imagemagick and so on.
Since nobody else posted the translation to GTK3, here you go:
from gi.repository import Gdk
win = Gdk.get_default_root_window()
h = win.get_height()
w = win.get_width()
print ("The size of the window is %d x %d" % (w, h))
pb = Gdk.pixbuf_get_from_window(win, 0, 0, w, h)
if (pb != None):
pb.savev("screenshot.png","png", (), ())
print("Screenshot saved to screenshot.png.")
else:
print("Unable to get the screenshot.")
Better later than never. I got stuck with get_from_drawable() but later found the documentation about its deprecation.
from gi.repository import Gdk
window = Gdk.get_default_root_window()
x, y, width, height = window.get_geometry()
print("The size of the root window is {} x {}".format(width, height))
# get_from_drawable() was deprecated. See:
# https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.7
pb = Gdk.pixbuf_get_from_window(window, x, y, width, height)
if pb:
pb.savev("screenshot.png", "png", (), ())
print("Screenshot saved to screenshot.png.")
else:
print("Unable to get the screenshot.")