Python Gtk TextView insert text at end

6.2k Views Asked by At

I want to insert text to a textbuffer at the end... Im using this: gtk.TextBuffer.insert_at_cursor

But if I clicking into the text there the new appears at the cursor...

How can i add text at the end?

1

There are 1 best solutions below

0
Uyghur Lives Matter On BEST ANSWER

Try using gtk.TextBuffer.insert() with gtk.TextBuffer.get_end_iter(). Example:

# text_buffer is a gtk.TextBuffer
end_iter = text_buffer.get_end_iter()
text_buffer.insert(end_iter, "The text to insert at the end")

NOTE: Once you insert into text_buffer, end_iter is invalidated so make sure to get a new reference to the end-iterator whenever you want to append to the end of the buffer.