Search code examples
python-2.7gtkgtk3pygobject

How do I take a screenshot using GdkPixbuf?


Using PyGTK, I used to be able to take a screenshot using gtk.gdk.pixbuf.get_from_drawable.

I can't seem to figure out how to do that using PyGObject and GdkPixbuf. I've tried get_from_drawable and get_from_window but neither work in PyGObject.

Thanks in advance.


Solution

  • Use Gtk.OffscreenWindow:

    offscreen_window = Gtk.OffscreenWindow()
    offscreen_window.add(widget_that_needs_screenshotting)
    pixbuf = offscreen_window.get_pixbuf()