#!/usr/bin/env python

import gtk

def prepare():
    w = gtk.Window()
    w.connect('destroy', lambda w: gtk.main_quit())
    vbox = gtk.VBox()
    w.add(vbox)
    label = gtk.Label('')
    vbox.pack_start(label)
    textview = gtk.TextView()
    textview.set_size_request(300, 20)
    vbox.pack_start(textview)
    def cb(event):
        if gtk.gdk.keyval_name(event.keyval) == 'Return':
            buf = textview.get_buffer()
            label.set_text(buf.get_text(*buf.get_bounds()))
            buf.set_text('')
            return True
        return False
    textview.connect('key-press-event', lambda w, event: cb(event))
    w.show_all()

if __name__ == '__main__':
    prepare()
    gtk.main()
