I recently read on of the answers written by respected Bryan Oakley(Tkinter adding line number to text widget) where he showed a sample code about solving the problem.