How to get the surface in pygtk drawing area?

245 views Asked by At

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?

1

There are 1 answers

0
mazznoer On BEST ANSWER

I found it.

surface = ctx.get_group_target()