bab bab - 8 months ago 47
Linux Question

Taking screenshot with python in linux (VM guest)

Following the answer to this similar stackoverflow question, I tried running this code

import gtk.gdk

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[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):"screenshot.png","png")
print "Screenshot saved to screenshot.png."
print "Unable to get the screenshot."

However, the resulting image is completely black. My environment is linux mint 16 running in virtualbox on a mac. Was the black image the result of running a linux vm, or is there another reason?


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.)