在 Tkinter 条目小部件中获取光标位置 [英] Getting Cursor position in Tkinter entry widget
问题描述
我的 tkinter 程序中有一个入口小部件.假设我在其中输入了大约 10 个单词,然后转到另一个条目小部件进行输入.现在,当我重新单击我的条目小部件 1(上一个)时,光标会根据单击位置转到该字符.如何获取该小部件的光标位置索引?我参考了 http://effbot.org/tkinterbook/entry.htm 文档但不能找到合适的获取光标位置的方法.
I've an entry widget in my tkinter program. Let's say I typed about 10 words in it and went to another entry widget for typing. Now when I click back on my entry widget 1 (previous one), cursor goes to the character as per click position. How do I get cursor position index for that widget ? I referred to http://effbot.org/tkinterbook/entry.htm documentation but couldn't find a suitable method for getting cursor position.
谢谢.
推荐答案
您可以使用 index
方法获取当前INSERT
位置的索引.
You can use the index
method to get the index of the current INSERT
position.
from Tkinter import *
def get_info():
print e.index(INSERT)
root = Tk()
e = Entry(root)
e.pack()
Button(root, text="get info", command=get_info).pack()
root.mainloop()
这篇关于在 Tkinter 条目小部件中获取光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!