我實現了一個日誌。這是在ScrolledWindow中使用TextBuffer的TextView。在例程中,我在此日誌中添加了一行新行。之後它應該滾動到最後一行。在Python中的GTK3程序上滾動到ScrolledWindow/TextView的末尾
def append_log(self, line):
self.textbuffer.insert(self.textbuffer.get_end_iter(), "\n"+line, -1)
# scrolling down
它應該是這樣的:http://www.physik.tu-dresden.de/~s9472632/log_manual.png
但它不工作。我試過下面的代碼。
# nothing happens
adj = self.scrolledwindow.get_vadjustment()
adj.set_value(adj.get_upper()-adj.get_page_size()) # same without subtraction (only upper or page_size)
self.scrolledwindow.set_vadjustment(adj) # with and without this line
。
# nothing happens
self.textview.scroll_to_iter(self.textbuffer.get_end_iter(), 0.0, False, 0.5, 0.5)
。
# works a bit but scroll bars cover the text (see picture below)
self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0.0, False, 0.5, 0.5)
圖片:http://www.physik.tu-dresden.de/~s9472632/log_scroll.png
看來scroll_to *(within_margin,use_align,xalign,yalign)的最後四個參數沒有結果的影響。
它是如何工作的?
Bye Markus
確保你使用add方法的孩子具有本地滾動功能。這是C api中的'container_add'。 – ergosys