【发布时间】:2019-01-17 18:12:48
【问题描述】:
我根据this answer 将ScrolledText 自动滚动 到最后。
现在我想仅在用户不手动滚动时自动滚动。
我一直在寻找类似这样的东西:self.text.offsetBottom(请参阅下面代码中的评论),但还没有找到。
有什么想法吗?谢谢!
import time
from Tkinter import *
import ScrolledText
class Example(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
self.text = ScrolledText.ScrolledText(self, height=6, width=40)
self.text.pack(side="left", fill="both", expand=True)
self.add_timestamp()
def add_timestamp(self):
self.text.insert("end", time.ctime() + "\n")
""" -----> HERE <----- """
# if self.text.offsetBottom > 0:
self.text.see("end")
self.after(1000, self.add_timestamp)
if __name__ == "__main__":
root =Tk()
frame = Example(root)
frame.pack(fill="both", expand=True)
root.mainloop()
【问题讨论】:
-
你希望
text.offsetBottom返回什么? -
@Goyo 例如
0如果没有偏移量。 :)
标签: python python-2.7 user-interface tkinter