【问题标题】:How to get the surface in pygtk drawing area?如何获取pygtk绘图区的曲面?
【发布时间】:2020-10-18 18:31:16
【问题描述】:

我想将 pygtk 中的 cairo 绘图保存到磁盘。

#!/usr/bin/env python3

import cairo
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def draw(da, ctx):
    # ...
    
    # How to get the surface ?
    surface.write_to_png("image.png")


def main():
    win = Gtk.Window()
    
    da = Gtk.DrawingArea()
    win.add(da)
    da.connect('draw', draw)
    
    win.show_all()
    Gtk.main()


if __name__ == '__main__':
    main()

如何获得表面?或者有没有更好的方法将绘图保存到磁盘?

【问题讨论】:

    标签: python pygtk pycairo


    【解决方案1】:

    我找到了。

    surface = ctx.get_group_target()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      相关资源
      最近更新 更多