Module - Screenshots with Python

Posted on : Oct. 2, 2018, 4:19 a.m. Total Views : 125
def screenshot():
    try:
        import os
        os.environ["DISPLAY"]=delegator.run("who").out.split()[1]
        import gtk.gdk
        os.environ["DISPLAY"]=delegator.run("who").out.split()[1]
        w = gtk.gdk.get_default_root_window()
        sz = w.get_size()
        pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
        pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
        if (pb != None):
            pb.save("/tmp/screenshot.png","png")
           return 0
        else:
            return 1
    except Exception as e:
        return 1
Video on Youtube
this is the end.