简体   繁体   中英

How to get the surface in pygtk drawing area?

I want to save cairo drawing in pygtk to disk.

#!/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()

How to get the surface ? Or is there any better method to save the drawing to disk?

我找到了。

surface = ctx.get_group_target()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM