在Python Gtk TextView中将文本插入到末尾

10

我想在文本缓冲区的末尾插入文本... 我使用的是:gtk.TextBuffer.insert_at_cursor

但是如果我点击到文本中,新文本将出现在光标处...

我该如何在末尾添加文本?

1个回答

12
尝试使用 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将无效,因此请确保在想要附加到缓冲区末尾时每次获取新的结束迭代器引用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接