Newby pango problem

John Hunter jdhunter at
Mon Aug 30 14:54:44 CEST 2004

>>>>> "Friedrich" == Friedrich Dimmling <f.dimmling at> writes:

    Friedrich> Hi, I would like to use pango.layout to display text in
    Friedrich> a pygtk2 project. However I could not manage to get the
    Friedrich> pango.layout object incorporated in my toplevel
    Friedrich> gtk.Window and have it displayed.

    Friedrich> If anyone could help me either with a minimal example
    Friedrich> like 'Hello World' displayed in italics in an
    Friedrich> pango.layout or the URL to a tutorial where I can find
    Friedrich> the relevant infos (the PyGtk tutorial seems not to
    Friedrich> contain it, unless I'm really blind)

Here is from my pygtk examples dir.  I wrote this a long
time ago, so it may not be the best or most modern usage, but it may
help you along your way

from __future__ import division
import pygtk
import gtk
from gtk import gdk
import pango

win = gtk.Window()
vbox = gtk.VBox()

figsize = 4,4
dpi = 72
def draw(widget):

    gc = widget.window.new_gc()

    context = widget.create_pango_context()
    layout  = widget.create_pango_layout('Some Text')
    desc = pango.FontDescription('Times 14')


    widget.window.draw_layout(gc, x=100, y=200, layout=layout)
    widget.window.draw_rectangle( gc, 1, 100,100,100,100)

def configure_event(widget, event):
    global pixmap
    pixmap = gtk.gdk.Pixmap(widget.window, 500, 500)

    return gtk.TRUE

def expose_event(widget, event):
    return gtk.TRUE

da = gtk.DrawingArea()
da.connect('configure_event', configure_event)
da.connect('expose_event', configure_event)

da.set_size_request(figsize[0]*dpi, figsize[1]*dpi)
vbox.pack_start(da, gtk.TRUE, gtk.TRUE)

def byebye(button):
    pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8,
    pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
                             0, 0, 0, 0, 500, 500)'somefile.png', 'png')
button = gtk.Button('Quit')
vbox.pack_start(button, gtk.TRUE, gtk.TRUE)
button.connect('clicked', byebye)


More information about the Python-list mailing list