I get the number of lines of a tkinter Text widget like this:
import Tkinter as Tk
def countlines(event):
print float(event.widget.index(Tk.END))-1
print event.widget.get("1.0", Tk.END).count("\n")
root = Tk.Tk()
root.geometry("200x200")
a = Tk.Text(root)
a.pack()
a.bind("<Key>", countlines)
root.mainloop()
Only problem : when you hit <Return>, the count of lines doesn't increase. You need to add some futher text in order that count of lines increases.
How to make that < Return > key increases the count of lines ?