Python Gtk TextView末尾插入文本

时间:2014-02-15 09:16:25

标签: python textview gtk gtk-textbuffer

我想在最后将文本插入文本缓冲区... 我正在使用这个:gtk.TextBuffer.insert_at_cursor

但是,如果我点击文本,光标会出现新的颜色......

如何在最后添加文字?

1 个答案:

答案 0 :(得分:8)

尝试将gtk.TextBuffer.insert()gtk.TextBuffer.get_end_iter()一起使用。例如:

# 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")

注意:一旦插入text_bufferend_iter就会失效,所以每当你想要附加到缓冲区的末尾时,一定要获得对end-iterator的新引用。