newbie: selecting text by script in Tkinter fails

Martin Franklin martin.franklin at
Tue Nov 6 22:54:32 CET 2001


Johnny deBris wrote:

> Hello!!
> I have a question about selecting text in a Tkinter Text-widget using
> the tag_remove and tag_add-methods: there is a small explanation on
> how it should be done in 'an Introduction to Tkinter', but I cannot
> get the work done the way the author proposes
> Can anybody tell me how I can select a piece of text from script? I'm
> working on a texteditor in Python, and this is part of a search-option
> I would like to add. For people who think they're suffering from
> deja-vu or something: I have posted a question quite similar to this
> one a few days ago, but no-one seemed to be able to or want to answer.
> (maybe a classical case of RTFM? If so, please tell me where to find
> that FM!! :)
> Thanx again,
> Guido Wesdorp
Here are a couple of functions that I user to 'show' my ;found' text   

    def find_text(self):
        if not pat:
            return, "insert")
        if self.found:
    def show(self):
        line, start = map(int, self.found.split('.'))
        self.parent.textarea.tag_add("found", "%d.%d" %(line, 
              start), "%d.%d" %(line, end))
        self.parent.textarea.tag_config("found", background='navy', 
        self.parent.textarea.mark_set("insert", "%d.%d" %(line, end+1))
        self.parent.textarea.see("%d.%d" %(line, start))


More information about the Python-list mailing list