Adding a Cairo object into a vbox using pygtk

Mr SZ sk8in_zombi at
Fri Jul 11 22:55:32 CEST 2008

Hi ,

I am trying to attach a cairo object into a vbox.I can pack a textbox with the following code:

    entry = gtk.Entry()
    entry.connect("activate", self.enter_callback, entry)
    entry.insert_text(" world", len(entry.get_text()))
    entry.select_region(0, len(entry.get_text()))
    self.vbox.pack_start(entry, True, True, 0)

but when I do the same for a cairo object I had created from the pycairo examples ,it wont.

        self.window = builder.get_object("mainwindow")
        self.vbox = builder.get_object("winvbox")
    # connect signals
    def cairorun(self,Widget):
    widget = Widget()
    self.vbox.pack_start(widget, True, True, 0)

class cairoshape(framework.Screen):
    def draw(self, cr, width, height):
    image = cairo.ImageSurface.create_from_png ("image.png")
    cr.set_source_surface (image, 0, 0)
    cr.paint ()

and the from the examples:

#! /usr/bin/env python
import pygtk
import gtk, gobject, cairo

# Create a GTK+ widget on which we will draw using Cairo
class Screen(gtk.DrawingArea):

    # Draw in response to an expose-event
    __gsignals__ = { "expose-event": "override" }

    # Handle the expose-event by drawing
    def do_expose_event(self, event):

        # Create the cairo context
        cr = self.window.cairo_create()

        # Restrict Cairo to the exposed area; avoid extra work
        cr.rectangle(event.area.x, event.area.y,
                event.area.width, event.area.height)

        self.draw(cr, *self.window.get_size())

    def draw(self, cr, width, height):
        # Fill the background with gray
        cr.set_source_rgb(0.5, 0.5, 0.5)
        cr.rectangle(0, 0, width, height)

# GTK mumbo-jumbo to show the widget in a window and quit when it's closed
def run(Widget):
    window = gtk.Window()
    window.connect("delete-event", gtk.main_quit)
    widget = Widget()

if __name__ == "__main__":

In short,I can attach the cairo widget to a main window but I'm unable to pack it into a vbox.


" life isn't heavy enough,it flies away and floats far above action"

      Start at the new Yahoo!7 for a better online experience.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list