Following the answer to this similar stackoverflow question, I tried running this code
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz,sz)
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz,sz)
if (pb != None):
print "Screenshot saved to screenshot.png."
print "Unable to get the screenshot."
It is the VM that is the issue here I'm pretty sure. At least it was for me.
There are several steps to figure out which part is messing up but most of them are with issues with the display on VM's having issues with the colormaps. so first use:
to get the colormap to use and replace the colormap in the original code. See if there's a change.
if that is a dead end I would suggest the following:
TURN OF YOUR VIDEO ACCELERATION <====Huge majority of issues fixed here
Roll Back then Update your video/graphics/3d drivers <==This is almost never the problem
Be sure you've got the newest release of pyscreenshot and retry screenshot
Let me know if it still isn't working and I'll send you the full Step-by-step (its quite long and jumps around a lot but it covers just about everything with this issue.)