self text tag_add(selindex index self text tag_remove(sel' 'endtag all text in the widget select from index up to index remove selection from all text the first line here creates new tag that names all text in the widget--from start through end positions the second line adds range of characters to the built-in sel selection tag--they are automatically highlightedbecause this tag is predefined to configure its members that way the third line removes all characters in the text string from the sel tag (all selections are unselectednote that the tag_remove call just untags text within the named rangeto really delete tag completelycall tag_delete instead also keep in mind that these calls apply to tags themselvesto delete actual text use the delete method shown earlier you can map indexes to tags dynamicallytoo for examplethe text search method returns the row column index of the first occurrence of string between start and stop positions to automatically select the text thus foundsimply add its index to the builtin sel tagwhere self text search(targetinsertendpastit where ('+%dclen(target)self text tag_add(selwherepastitself text focus(search from insert cursor index beyond string found tag and select found string select text widget itself if you want only one string to be selectedbe sure to first run the tag_remove call listed earlier--this code adds selection in addition to any selections that already exist (it may generate multiple selections in the displayin generalyou can add any number of substrings to tag to process them as group to summarizeindexesmarksand tag locations can be used anytime you need text position for instancethe text see method scrolls the display to make position visibleit accepts all three kinds of position specifiersself text see(' 'self text see(insertself text see(sel_firstscroll display to top scroll display to insert cursor mark scroll display to selection tag text tags can also be used in broader ways for formatting and event bindingsbut 'll defer those details until the end of this section adding text-editing operations example - puts some of these concepts to work it extends example - to add support for four common text-editing operations--file savetext cut and pasteand string find searching--by subclassing scrolledtext to provide additional buttons and methods the text widget comes with set of default keyboard bindings that perform some common editing operationstoobut they might not be what is expected on every platformit' more common and user friendly to provide gui interfaces to editing operations in gui text editor text