Re: Transferring tags from one Text() to another

Michael Lange <[email protected]>
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>
Hi,

On Wed, 10 Feb 2016 16:30:18 -0700
Bob Greschke <[email protected]> wrote:

> I write stuff to a Text() and some words and lines are different colors
> or are links (binds) using Tags. I can Text().get(0.0, END), get all of
> the text, then insert that in another Text() to make a copy, but how do
> I get/transfer the other "formatting" info? The binds aren't real
> important, but the different colored text would be nice.

I think you could apply the same calls to tag_configure() and tag_bind()
to both widgets and then try something like this to copy the tags from
one widget to the other (at least as a starting point):

def copy_tags():
    tags = t1.tag_names()
    for tag in tags:
        r = t1.tag_ranges(tag)
        if r:
            t2.tag_add(tag, *r)

If the parts of text that are "tagged" are not at the same position in
t2 you would of course have to shift each element of
t1.tag_ranges() by an offset of t2.index.insert() or so.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Murder is contrary to the laws of man and God.
		-- M-5 Computer, "The Ultimate Computer", stardate 4731.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.