user422100 user422100 - 1 year ago 107
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 Source
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()

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download