0
votes

I have recently started using glade, python gtk+ and cairo to build GUI apps. I have constructed a DrawingArea widget in which I have used pixbuf to paint an image. However when i try to draw shapes on the image, the shapes get drawn behind the image.

def on_draw(self, wid, cr):
    #cr.rectangle(1500, 300, 400, 800)
    #cr.stroke()
    self.pb = GdkPixbuf.Pixbuf.new_from_file_at_scale("image2.jpg", 1920, 1080, True)
    Gdk.cairo_set_source_pixbuf(cr, self.pb, 0, 0)
    cr.paint()

Is there any way possible to get the shapes on top of the image?

Sorry for such a silly question. I am just new to this.

1

1 Answers

1
votes

Why don't you just draw the shape ontop of the image instead of behind it?

So, instead of, well, drawing the shape first and then drawing the image, do it the other way around. First draw the image and then the shape.

def on_draw(self, wid, cr):
    self.pb = GdkPixbuf.Pixbuf.new_from_file_at_scale("image2.jpg", 1920, 1080, True)
    Gdk.cairo_set_source_pixbuf(cr, self.pb, 0, 0)
    cr.paint()
    cr.set_source_rgb(0, 0, 0)
    cr.rectangle(1500, 300, 400, 800)
    cr.stroke()