clearing newline char from gtk.Textbuffer
Question
I have a gtk.TextBuffer which is supposed to be cleared after pressing Enter, similar to the input box on most chat programs. I'm just setting the buffer back to a blank string. The newline character from Enter isn't removed though, and a blank line ends up above the cursor during the next input. Moving the cursor to the first gtk.Iter doesn't help.
Solution
By default, "gobject.connect()"
callback is called before the default handler. You need to use "gobject.connect_after()"
.
def insert_text_cb(text_buffer, position, text, lenght):
if text == '\n':
text_buffer.set_text('')
text_view = gtk.TextView()
text_view.get_buffer().connect_after('insert-text', insert_text_cb)
OTHER TIPS
Are you sure you're trigger on the proper event? Also try connecting it after.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow