def main():
    button = gtk.Button('Hello')
scroll_win = gtk.ScrolledWindow()
scroll_win.add(button)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(scroll_win)
win.show_all()
gobject.timeout_add(1000, drawWindow, win)

def drawWindow(win):
    width, height = win.get_size()
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
screenshot = pixbuf.get_from_drawable(win.window, win.get_colormap(), 0, 0,
    0, 0, width, height)
screenshot.save('screenshot.png', 'png')
return False
if __name__ == '__main__':
    main()
gtk.main()
Creating a screenshot of a gtk.Window