[Tkinter-discuss] Transferring tags from one Text() to another
Michael Lange
klappnase at web.de
Wed Feb 10 19:23:01 EST 2016
Hi,
On Wed, 10 Feb 2016 16:30:18 -0700
Bob Greschke <bob at passcal.nmt.edu> 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
More information about the Tkinter-discuss
mailing list