Python Tkinter 文本区域将光标设置为结束 [英] Python Tkinter Text Area set cursor to end

查看:35
本文介绍了Python Tkinter 文本区域将光标设置为结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Tkinter Text() 对象,我使用 .insert(END, string) 向它附加行.当文本填满可用区域时,我希望它向下滚动以在视图中显示文本的底行,但它不会滚动(这意味着用户必须自己滚动才能看到最新的文本).我已经查看了 mark_set() 方法,但我似乎无法弄清楚如何将光标移至最后一项文本的索引.

I have a Tkinter Text() object and I append lines to it using .insert(END, string). When the text fills the available area, I'd expect it to scroll down to show the bottom line of text in the view, but it doesn't scroll (meaning the user has to scroll themselves to see the latest text). I've had a look at the mark_set() method but I can't seem to figure out how to get the cursor to the index of the last item of text.

任何帮助将不胜感激:)

Any help would be appreciated :)

推荐答案

和 Tkinter 一样,有很多方法可以做到这一点,但一种最简单:Text.see:

As usual with Tkinter, there are a number of ways to do this, but one is the easiest: Text.see:

text.insert(END, "spam\n")
text.see(END)

如果您想确保新文本的开始可见,而不是它的结尾,或者如果您只想在结尾已经预先可见或文本是否处于活动状态等,您可能需要查看其他选项:scan_mark/scan_dragto,或yview 和朋友.

If you want to make sure the start of the new text is visible, not the end of it, or if you only want to do this if the end was already visible beforehand or if the text is active, etc., you may need to look at the other options: scan_mark/scan_dragto, or yview and friends.

这篇关于Python Tkinter 文本区域将光标设置为结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆