3

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.

liberforce
  • 11,189
  • 37
  • 48
Steve Gricci
  • 133
  • 1
  • 6

1 Answers1

2

Use Gtk.OffscreenWindow:

offscreen_window = Gtk.OffscreenWindow()
offscreen_window.add(widget_that_needs_screenshotting)
pixbuf = offscreen_window.get_pixbuf()
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Hrm, I was looking to take a screenshot of a user selected area, offscreen_window doesn't seem to let me specify an x, y, width, height. – Steve Gricci Jan 28 '13 at 02:15
  • You didn't specify that in your question - but you can always clip the pixbuf after taking the screenshot to achieve that. – ptomato Jan 28 '13 at 07:32
  • Agreed, I didn't specify that. How can I take a portion of the screen to add to offscreen_window, when it takes a widget? – Steve Gricci Jan 28 '13 at 16:09
  • You can't, it only takes a widget. But you can still clip the pixbuf to the desired dimension. If you want anything else, you will have to get into Xlib. – ptomato Jan 28 '13 at 19:24