Hello all,

I am trying to use gtk.DrawingArea to draw an orange rectangle, using
some of the information at
http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html.

I have included a sample of my code below, which draws a black
rectangle.  However, I cannot get it to accept the color information
from gc.

Can anyone tell me what I'm doing wrong?

Thanks in advance.

--------------------------------------------------------------------------------

import gtk

class CustomDrawingArea(gtk.DrawingArea):
    def __init__(self):
        gtk.DrawingArea.__init__(self)
        self.connect("expose_event", self.expose)

    def expose(self, widget, event):
        self.context = widget.window.cairo_create()
        self.draw(self.context)

        return False

    def draw(self, context):
        drawable = self.window
        gc = drawable.new_gc()

        gc.foreground = gtk.gdk.color_parse("orange")

        gc.fill = gtk.gdk.SOLID

        drawable.draw_rectangle(gc, True, x=100, y=100, width=10, height=50)

def main():
    window = gtk.Window()
    window.set_size_request(500, 500)

    cda = CustomDrawingArea()

    window.add(cda)
    window.connect("destroy", gtk.main_quit)
    window.show_all()

    gtk.main()

if __name__ == "__main__":
    main()
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to