import tkinter as tk def clickedOnTest(event, test): start = test.index(('@%s,%s wordstart' % (event.x, event.y))) end = test.index(('@%s,%s wordend' % (event.x, event.y))) word = test.get(start, end) print("%s - %s" % (start, word)) root = tk.Tk() # No tags, expected behavior test = tk.Text(root) test.bind("", lambda e: clickedOnTest(e, test)) test.grid() test.insert(1.0, "[testing]\n**testing]") # Words tagged, unexpected behavior test2 = tk.Text(root) test2.grid() test2.bind("", lambda e: clickedOnTest(e, test2)) test2.insert(1.0, "[testing]\n*testing]") test2.tag_add("testing1", 1.1, 1.8) test2.tag_add("testing2", 2.1, 2.8) # not at edge and tagged, expected behavior test3 = tk.Text(root) test3.grid() test3.bind("", lambda e: clickedOnTest(e, test3)) test3.insert(1.0, "word [testing]\n[[testing]") test3.tag_add("testing3", 1.6, 1.13) test3.tag_add("testing4", 2.2, "2.9") root.mainloop()