我正在用gtk和python创建一个应用程序。
在应用程序中,我有一个滚动窗口,在其中我有一个textview。
当我在文本缓冲区中使用set_text()
时,滚动条会滚动到顶部。
我想要的是当我使用set_text()
时,滚动条将滚动到底部。
或者换句话说我想控制滚动条到底部。
怎么做?
感谢您的帮助!
答案 0 :(得分:1)
我相信有两种方式。
set_text
gtk3-demo
部分的Text Widget -> Automatic Scrolling
应用中找到更复杂的示例。有以下几行: /* If we want to scroll to the end, including horizontal scrolling,
* then we just create a mark with right gravity at the end of the
* buffer. It will stay at the end unless explicitly moved with
* gtk_text_buffer_move_mark.
*/
gtk_text_buffer_create_mark (buffer, "end", &iter, FALSE);
然后:
/* Get "end" mark. It's located at the end of buffer because
* of right gravity
*/
mark = gtk_text_buffer_get_mark (buffer, "end");
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
/* and insert some text at its position, the iter will be
* revalidated after insertion to point to the end of inserted text
*/
// Extra code removed
/* Now scroll the end mark onscreen.
*/
gtk_text_view_scroll_mark_onscreen (textview, mark);