Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Cursor position in Tkinter entry widget

Tags:

python

tkinter

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.

Thanks.

like image 679
dhruvvyas90 Avatar asked Jun 24 '15 10:06

dhruvvyas90


1 Answers

You can use the Entry.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()
like image 98
tobias_k Avatar answered Sep 20 '22 17:09

tobias_k