【问题标题】:PyGTK+3 (PyGObject) to create screenshot?PyGTK+3 (PyGObject) 创建截图?
【发布时间】:2013-12-28 15:40:36
【问题描述】:

我在 google 上搜索了 3 天,如何使用 PyGTK+3 创建屏幕截图? 有关于pyqt、pygtk+2、wx和PIL的galizion教程。

顺便说一句,我不需要像 scrot、imlib2、imagemagick 等外部程序。

【问题讨论】:

  • 没有 PyGtk+3 这样的东西。我想你的意思是 PyGObject。如果您添加指向 PyGtk 教程的链接,我可以为您将其翻译成 PyGObject,这在当时非常简单。

标签: python linux pygtk pygobject


【解决方案1】:

由于没有其他人将翻译发布到 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.")

【讨论】:

    【解决方案2】:

    迟到总比没有好。我被 get_from_drawable() 卡住了,但后来找到了关于它的弃用的文档。

    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:
    # https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.7
    pb = Gdk.pixbuf_get_from_window(window, x, y, width, height)
    
    if pb:
        pb.savev("screenshot.png", "png", (), ())
        print("Screenshot saved to screenshot.png.")
    else:
        print("Unable to get the screenshot.")
    

    【讨论】:

    • 我是 HexSFd,stackoverflow 阻止了我以前提出“低质量问题”的帐户,并且无法回复您的帖子。谢谢 Havok,祝你一切顺利。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 2012-07-20
    • 1970-01-01
    相关资源
    最近更新 更多