import sys from Tkinter import * mle = None def main(): global text1 root = Tk() qbutton = Button(root) qbutton['text'] = 'quit' qbutton['command'] = quit_callback qbutton.pack() sbutton = Button(root) sbutton['text'] = 'show selection' sbutton['command'] = show_callback sbutton.pack() text1 = Text(root) text1.pack() root.mainloop() def quit_callback(): sys.exit(0) def show_callback(): global text1 ranges = text1.tag_ranges(SEL) start = ranges[0] stop = ranges[1] print repr(text1.get(start, stop)) main()
The word SEL refers to the current selection and this is in fact associated with a tag. I used the "Introduction to TKinter" on www.pythonware.com/library/tkinter/introduction to find out.