PyGTK + 3(PyGObject)创建截图?

Hex*_*SFd 3 python linux pygtk pygobject

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

顺便说一下,我不需要像scrot,imlib2,imagemagick等外部程序.

gia*_*nmt 7

由于没有其他人将翻译发布到GTK3,所以你去:

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.")
Run Code Online (Sandbox Code Playgroud)