1from gtk import gdk 2from PIL import Image 3 4 5class Capturer(object): 6 "A class that will take a screenshot of a single pixel on a GTK system." 7 def __init__(self, w=None, h=None): 8 self._w = w if w else gdk.screen_width() 9 self._h = h if h else gdk.screen_height()1011 self._window = gdk.get_default_root_window()12 self._pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, self._w, self._h)1314 def screenshot(self, x, y):15 pb = self._pb.get_from_drawable(self._window, self._window.get_colormap(), x, y, 0, 0, self._w, self._h)16 image = Image.frombuffer('RGB', (self._w, self._h), pb.get_pixels(), 'raw', 'RGB', pb.get_rowstride(), 1)17 return image