2014-02-15 53 views
4

插入文本我想在末尾插入文本到textbuffer ... 进出口使用此:gtk.TextBuffer.insert_at_cursorPython的基于GTK的TextView在结束

但如果我点击到文本有光标处新出现..

如何在最后添加文本?

回答

5

尝试使用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将失效,从而确保无论何时你要追加到缓冲区的末尾,以获得新的参考,以最终迭代器。