drawing a pixbuf onto a drawing area using pygtk and glade

偶尔善良 提交于 2019-12-06 04:54:02

You can make use of cairo to do this. First, create a gtk.DrawingArea based class, and connect the expose-event to your expose func.

class draw(gtk.gdk.DrawingArea):
    def __init__(self):
        self.connect('expose-event', self._do_expose)
        self.pixbuf = self.gen_pixbuf_from_file(PATH_TO_THE_FILE)

    def _do_expose(self, widget, event):
        cr = self.window.cairo_create()
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.set_source_rgb(1,1,1)
        cr.paint()
        cr.set_source_pixbuf(self.pixbuf, 0, 0)
        cr.paint()

This will draw the image every time the expose-event is emited.

Michael

I found out I just need to get the function to call another expose event with widget.queue_draw() at the end of the function. The function was only being called once at the start, and there were no nodes available at this point so nothing was being drawn.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!