Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Call Back For Enter key of GtkTextView?

Tags:

python

pygtk

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

like image 409
user422100 Avatar asked Nov 19 '25 21:11

user422100


1 Answers

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?!

like image 172
saeedgnu Avatar answered Nov 22 '25 10:11

saeedgnu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!