This example requires SimpleGladeApp.py, don't forget to download it.
#!/usr/bin/env python # -*- coding: UTF8 -*- from SimpleGladeApp import SimpleGladeApp import gtk import cairo import cairo.gtk class Cairo3GladeApp(SimpleGladeApp): def new(self): self.ctx = cairo.Context() def on_expose(self, area, event): top, left, width, height = event.area cairo.gtk.set_target_drawable(self.ctx, self.drawingarea1.window) self.width, self.height = self.drawingarea1.window.get_size() self.ctx.set_rgb_color(0.4, 0.7, 0.9) self.ctx.set_alpha(0.8) self.ctx.rectangle(top, left, width, height) self.ctx.fill() self.ctx.set_line_width(17) self.draw_rectangle() self.ctx.stroke() def draw_rectangle(self, *args): x = self.width/4 y = self.height/4 w = self.width/2 h = self.height/2 self.ctx.set_rgb_color(0,0,0) self.ctx.rectangle(x, y, w, h) if self.check_5.get_active(): self.ctx.stroke() if self.check_4.get_active(): self.ctx.fill() if self.check_6.get_active(): self.ctx.save() self.ctx.set_rgb_color(3, 0.2, 0.2) self.ctx.fill() self.ctx.restore() self.ctx.stroke() def on_clicked(self, widget): self.drawingarea1.queue_draw() if self.check_1.get_active(): self.ctx.set_line_join(cairo.LINE_JOIN_ROUND) else: self.ctx.set_line_join(cairo.LINE_JOIN_MITER) if self.check_2.get_active(): self.ctx.set_line_join(cairo.LINE_JOIN_BEVEL) if self.check_3.get_active(): self.ctx.set_line_join(cairo.LINE_JOIN_MITER) if self.check_7.get_active(): self.ctx.set_dash([30, 5], 0) else: self.ctx.set_dash([30,0], 0) app = Cairo3GladeApp('cairo3gladeapp.glade') app.run()