在Linux上通过Python脚本拍摄屏幕截图 [英] Take a screenshot via a Python script on Linux

查看:413
本文介绍了在Linux上通过Python脚本拍摄屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过python脚本截取屏幕截图,并毫不干扰地保存它.

I want to take a screenshot via a python script and unobtrusively save it.

我只对Linux解决方案感兴趣,应该支持任何基于X的环境.

I'm only interested in the Linux solution, and should support any X based environment.

推荐答案

此方法无需使用scrot或ImageMagick.

This works without having to use scrot or ImageMagick.

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."

http://ubuntuforums.org/showpost.php?p=借来的2681009& postcount = 5

这篇关于在Linux上通过Python脚本拍摄屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆