[pygtk] Colors in cairo

M.B. spooky.ln at tbs-software.com
Mon Oct 27 02:48:31 WST 2008


hi all,
please tell me what i doing wrong with setting colors into cairo context.
here is my quick ugly code:

import gtk, cairo
class MyWin(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)
        self.connect("destroy", gtk.main_quit)
        self.set_default_size(200, 300)
        vbox = gtk.VBox()
        self.button = gtk.ColorButton()
        vbox.pack_start(self.button, False, True)
        self.area = gtk.DrawingArea()
        vbox.pack_start(self.area)
        self.area.connect("expose-event", self.redraw_all)
        self.add(vbox)
        self.show_all()
        
    def redraw_all(self, *args):
        ctx = self.area.window.cairo_create()
        color = self.button.get_color()
        ctx.set_source_rgb(color.red, color.green, color.blue)
        ctx.rectangle(0, 0, 200, 200)
        ctx.fill()
        
a = MyWin()
gtk.main()


thanks


More information about the pygtk mailing list