Displaying text using a Pango::Layout in GTK2

#! /usr/bin/env ruby

# file: text.rb

require 'gtk2'

area = Gtk::DrawingArea.new

#area.set_size_request(100,100)
area.signal_connect("expose_event") do
  layout = Pango::Layout.new(Gdk::Pango.context)
  layout.font_description = Pango::FontDescription.new('Sans 20')
  layout.text = 'xyz'

  area.window.draw_layout(area.style.fg_gc(area.state), x=50, y=50, layout)

end

Gtk::Window.new.add(area).show_all

Gtk.main


Screenshot

Screenshot of text displayed in a GTK2 application

Resources