Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to ignore some key events in a text view, now i do the following

def on_key_press_event(self,source,event):
    keyname = Gdk.keyval_name(event.keyval)
            tv = self.builder.get_object('txtMsg')
            buf = tv.get_buffer()
            msg = buf.get_text(buf.get_start_iter(),buf.get_end_iter(),self)

Is there any function equivalent to Java function event.consume() in python?

share|improve this question
@LordofTime Programming (development) questions are explicitly listed in the FAQ as reasonable questions to ask here. If it were a general Python question, vs. how to use GTK+ in Python, I might agree. – dobey Jul 6 '12 at 17:28
up vote 2 down vote accepted

To stop an event from propagating (unless the event has been set up using connect_after), you can run


For instance, if I connected the key-press-event like this:

self.textview.connect("key-press-event", self.on_key_press)

I can stop it propagating like this:

def on_key_press(self, widget, event):
share|improve this answer
Thank you very much :-), Problem Solved – Vishnu V Jul 7 '12 at 0:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.