Jack_of_All_Trades
Jack_of_All_Trades

Reputation: 11468

Capturing screenshots with Python in Windows and Linux

Is there any python library which can get print screenshot on both linux and windows? Any help will be appreciated.

Upvotes: 0

Views: 583

Answers (2)

Zain Khan
Zain Khan

Reputation: 3793

I have googled a bit and saw this on a forumn.

import gtk.gdk

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])
if (pb != None):
    pb.save("screenshot.png","png")
    print "Screenshot saved to screenshot.png."
else:
    print "Unable to get the screenshot."

The link to the stackoverflow answer is this

Upvotes: 0

Zain Khan
Zain Khan

Reputation: 3793

The library Castro can be used for your cause.

Here is a sample code from the documentation

from castro import Castro
c = Castro()
c.start()
# Do something awesome!
c.stop()

Upvotes: 1

Related Questions