Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The below code work perfectly when I run it as a console application

import gtk.gdk
import time

w = gtk.gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])

ts = time.time()
filename = "screenshot"
filename += str(ts)
filename += ".png"

if (pb != None):,"png")
    print "Screenshot saved to "+filename
    print "Unable to get the screenshot." 

But now I when I used it in a ubuntu application (using the quickly and glade) it is giving me error messages

 WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-O1o56xxlHA: Connection refused
/usr/lib/python2.7/dist-packages/gobject/ Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/ Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
  from gtk import _gtk
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/ Warning: g_type_get_qdata: assertion `node != NULL' failed
  from gtk import _gtk

How can I improve this code to work in GUI based application

EDIT What I have done to change the code

from gi.repository import Gdk, GdkX11, Gtk

        w = Gdk.get_default_root_window()
        geo = w.get_geometry()
        pb =,False,8,geo[2],geo[3])
        pb = pb.gdk_pixbuf_get_from_window(w,0,0,geo[2],geo[3])       
        pixbuf = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,geo[2],geo[3])       "xdfgxfdgdfxgfdx.png","png")
        print "The size of the window is %d x %d" % sz
        pix = GdkPixbuf.Pixbuf.gdk_pixbuf_get_from_window(root_window, 0, 0, 500, 500)
        pix = GdkPixbuf.gdk_pixbuf_get_from_window(window,0,0,500,500);

       ts = time.time()
       filename = "screenshot"
       filename += str(ts)
       filename += ".png"

       if (pix != None):
           print "Screenshot saved to "+filename
           print "Unable to get the screenshot." 

But still it is giving me error

(0, 0, 1366, 768)
<Pixbuf object at 0x2966410 (GdkPixbuf at 0x2e42d90)>
Traceback (most recent call last):
  File "/home/srs/projectob-team/projectob_team/", line 63, in on_start_clicked
    pb = pb.gdk_pixbuf_get_from_window(w,0,0,geo[2],geo[3])       
AttributeError: 'Pixbuf' object has no attribute 'gdk_pixbuf_get_from_window'
share|improve this question

The correct way to take an Screenshot using PyGobject (the Gtk version used by Quickly) is:

from gi.repository import Gdk

window = Gdk.get_default_root_window()
x, y, width, height = window.get_geometry()

print("The size of the root window is {} x {}".format(width, height))

# get_from_drawable() was deprecated. See:
pb = Gdk.pixbuf_get_from_window(window, x, y, width, height)

if pb:
    pb.savev("screenshot.png", "png", (), ())
    print("Screenshot saved to screenshot.png.")
    print("Unable to get the screenshot.")

The first version you posted is for the older PyGtk. So it works on console because it only loads PyGtk. In Quickly apps, PyGobject is loaded, and you cannot load both. You got stuck looking for get_from_drawable(), see:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.