#!/usr/bin/env python2

from gi.repository import Gtk

def on_selection_changed (sel, ls):
    selected = ls.get(sel.get_selected()[1], 0)[0]
    print selected

window = Gtk.Window()
window.connect("destroy", lambda q: Gtk.main_quit())

liststore = Gtk.ListStore(str)
liststore.append(["Do not click me!"])
liststore.append(["But click me!"])
liststore.append(["Or me!"])

box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

button = Gtk.Button(label="something to take initial focus")
treeview = Gtk.TreeView(model=liststore)

window.add(box)
box.add(button)
box.add(treeview)

treeviewcolumn = Gtk.TreeViewColumn("Item")
treeview.append_column(treeviewcolumn)
cellrenderertext = Gtk.CellRendererText()
treeviewcolumn.pack_start(cellrenderertext, True)
treeviewcolumn.add_attribute(cellrenderertext, "text", 0)

treeviewselection = treeview.get_selection()

treeviewselection.connect("changed", on_selection_changed, liststore)

window.show_all()

Gtk.main()
