You could connect Gtk.Entry
to either "key-press-event"
or/and "key-release-event"
to receive notification about the key being pressed or released for the entry widget. The callback will be called when entry receives key-press/release events for which it has to be in focus. To to check if Escape
key has been pressed you can make use of the event passed to the callback. You can check the keyval (which is associated with Gdk.Event.KEY_PRESS
and Gdk.Event.KEY_RELEASE
). You can make use of Gdk.KEY_*
to check for the value of the key which was pressed or released. You can try something on the lines of:
...
def on_key_release(self, widget, ev, data=None):
if ev.keyval == Gdk.KEY_Escape: #If Escape pressed, reset text
widget.set_text("")
...
def __init__(self):
Gtk.Window.__init__(self)
editor = Gtk.Entry()
editor.connect("key-release-event", self.on_key_release)
self.add(editor)
There is fair amount of documentation available online to aid you.
Hope this helps!