user422100 user422100 - 4 months ago 19
Python Question

How to Set Call Back For Enter key of GtkTextView?

how can I set call back on enter key of GtkTextView Widget and set TextView to work like gtk.entry (single-line)?

Answer
import gtk

tv = gtk.TextView()

def keyPress(widget, event):
    if gtk.gdk.keyval_name(event.keyval) == 'Return':
        ## do something
        return True
    return False

tv.connect('key-press-event', keyPress)

win = gtk.Dialog()
win.vbox.pack_start(tv)
win.vbox.show_all()
win.run()

But a question: If don't want multi-line input, so why you are using TextView instead of Entry?!