PyGTK + 3(PyGObject)创建屏幕截图? [英] PyGTK+3 (PyGObject) to create screenshot?

查看:83
本文介绍了PyGTK + 3(PyGObject)创建屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了3天的时间在Google中搜索,如何使用PyGTK + 3创建屏幕截图? 有关于pyqt,pygtk + 2,wx和PIL的gallizion教程.

I've spend past 3 days searching in google, how can I create a screenshot with PyGTK+3 ? There are gallizion tutorials about pyqt,pygtk+2,wx and PIL.

顺便说一句,我不需要外部程序,例如scrot,imlib2,imagemagick等.

By the way, I don't need external programs like scrot, imlib2, imagemagick and so on.

推荐答案

由于没有人将翻译发布到GTK3,因此您可以进行以下操作:

Since nobody else posted the translation to GTK3, here you go:

from gi.repository import Gdk

win = Gdk.get_default_root_window()
h = win.get_height()
w = win.get_width()

print ("The size of the window is %d x %d" % (w, h))

pb = Gdk.pixbuf_get_from_window(win, 0, 0, w, h)

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

这篇关于PyGTK + 3(PyGObject)创建屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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