我正在写一个像应用程序一样的简单画面:
#!/usr/bin/env python3
from gi.repository import Gtk
class Application(Gtk.Window):
def __init__(self):
super().__init__(Gtk.WindowType.TOPLEVEL, title='paint')
self.connect('destroy', self.__on_destroy)
vbox = Gtk.VBox()
drawing_area = Gtk.DrawingArea()
drawing_area.conenct('draw', self.__on_draw)
vbox.pack_start(drawing_area, True, True, 2)
self.add(vbox)
self.show_all()
def __on_draw(self, widget, g):
g.set_source_rgb(200, 0, 0)
g.move_to(16, 0)
g.line_to(16, 32)
g.stroke()
def save_to_file(self, filename):
# How to get pixels from drawing_area?
pass
def __on_destroy(self, e):
Gtk.main_quit()
app = Application()
Gtk.main()
现在我要保存用户绘图。如何访问Gtk.DrawingArea小部件中的像素?