在文本小部件中设置光标位置 [英] Set cursor position in a Text widget

查看:41
本文介绍了在文本小部件中设置光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Tkinter Text 小部件中设置光标位置?我还没有发现任何非常有用的东西.

Is it possible to set the cursor position in a Tkinter Text widget? I'm not finding anything terribly useful yet.

我能做的最好的事情是在某个 xy 坐标处发出 事件,但是这是一个像素数量,而不是一个字母数量.

The best I've been able to do is emit a <Button-1> and <ButtonRelease-1> event at a certain x-y coordinate, but that is a pixel amount, not a letter amount.

推荐答案

If "text", "line", and "column"是您的文本对象,所需的文本行和所需的列变量分别是:

If "text", "line", and "column" are your text object, the desired text line and desired column variables are, respectively:

text.mark_set("insert", "%d.%d" % (line + 1, column + 1))

如果您不想关心行号……好吧,您必须这样做.

If you would not like to care about the line number... well, you have to.

完整文档位于:http://effbot.org/tkinterbook/文本.htm

这篇关于在文本小部件中设置光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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