def grab(self, bbox=None):
w = Gdk.get_default_root_window()<EOL>if bbox is not None:<EOL><INDENT>g = [bbox[<NUM_LIT:0>], bbox[<NUM_LIT:1>], bbox[<NUM_LIT:2>] - bbox[<NUM_LIT:0>], bbox[<NUM_LIT:3>] - bbox[<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>g = w.get_geometry()<EOL><DEDENT>pb = Gdk.pixbuf_get_from_window(w, *g)<EOL>if pb.get_bits_per_sample() != <NUM_LIT:8>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif pb.get_n_channels() != <NUM_LIT:3>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>pixel_bytes = pb.read_pixel_bytes().get_data()  <EOL>width, height = g[<NUM_LIT:2>], g[<NUM_LIT:3>]<EOL>return Image.frombytes(<EOL>'<STR_LIT>', (width, height), pixel_bytes, '<STR_LIT>', '<STR_LIT>', pb.get_rowstride(), <NUM_LIT:1>)<EOL>
Grabs an image directly to a buffer.

        :param bbox: Optional tuple or list containing (x1, y1, x2, y2) coordinates
            of sub-region to capture.
        :return: PIL RGB image
        :raises: ValueError, if image data does not have 3 channels (RGB), each with 8
            bits.
        :rtype: Image