I am really not that good at Python, but give this a go. What I think is happening is although our redraws were done when we did the screen shot and had nothing else to do, other applications were still doing their redraws and they still had the remains of our windows image. To get around this I have used a time-out of 1 second instead of waiting for our work to be done. Hopefully in this time we would have done our work to destroy the window and the other applications would have done their redraws.
I am not sure their is a way to wait for all other applications to do their redraws. If there is then I am sure it would be pretty low level possibly at the X11 level.
Code:
#!/usr/bin/env python
from gi.repository import Gtk, GLib, Gdk
import time
def destroy_callback(widget):
print 'got destroy signal'
GLib.timeout_add(1000, timeout_callback)
def timeout_callback():
print 'got timout signal'
rw = Gdk.get_default_root_window()
rw_w = rw.get_width()
rw_h = rw.get_height()
p = Gdk.pixbuf_get_from_window(rw, 0, 0, rw_w, rw_h)
image = p.scale_simple(rw_w / 2, rw_h / 2, 2)
i = Gtk.Image.new_from_pixbuf(image)
w = Gtk.Window()
w.add(i)
w.show_all()
w.connect('destroy', lambda w: Gtk.main_quit())
return False
w = Gtk.Window()
w.set_default_size(400, 300)
w.set_position(Gtk.WindowPosition.CENTER)
w.connect('destroy', destroy_callback)
w.show_all()
Gtk.main()