-1

I made a text editor in it I made an status bar but a problem I did not know how to get cursor position details like notepad

Notepad image

Please help me

Naitik Singhal
  • 126
  • 1
  • 4
  • 3
    have you tried `text.index('insert')`? To get line and col use `line, col = text.index('insert').split('.')` – Art Jul 08 '21 at 06:35

1 Answers1

1

Is this what you were looking for?

import tkinter

master = tkinter.Tk()

labelframe = tkinter.LabelFrame( master, labelanchor = 's' )
labelframe.grid( row=0, column= 0, sticky = 'nsew' )

text = tkinter.Text( labelframe, width = 80, height= 24 )
text.grid( row=0, column= 0, sticky = 'nsew' )

def rowcol( ev = None ):
    r, c = text.index( 'insert' ).split( '.' )
    labelframe[ 'text' ] = f'{r} | {c}'

text.event_add( '<<REACT>>', *( '<Motion>', '<ButtonRelease>', '<KeyPress>', '<KeyRelease>' ) )
b = text.bind( '<<REACT>>', rowcol )
rowcol( ) # get the ball rolling
text.focus()

master.mainloop()
Derek
  • 1,916
  • 2
  • 5
  • 15