Tkinter & Text object

Matthew Dixon Cowles matt at mondoinfo.com
Wed Jun 20 12:43:01 EDT 2001


On Wed, 20 Jun 2001 12:14:17 -0400, Adonis <deltapigz at telocity.com>
wrote:

>anyone know how to set color to a line after it was added to a Text
>object?

>ive looked into the Tkinter documents and found text.mark_set("string",
>pos)

>but have no idea how to use it. a teeny example is all im looking for
>afterwards i can pick up from that point.

Tkinter is much less frustrating if you keep a copy of Fredrik Lundh's
excellent An Introduction to Tkinter nearby. It's at:

http://www.pythonware.com/library/tkinter/introduction/index.htm

But here's an example that I think does what you want:

>>> from Tkinter import *
>>> r=Tk()
>>> t=Text(r)
>>> t.pack()
>>> t.insert(END,"Wibble\n")
>>> t.insert(END,"Qux")
>>> t.tag_add("t1","1.0","1.end")
>>> t.tag_configure("t1",foreground="green")
>>> t.tag_add("t2","2.2","2.3")
>>> t.tag_configure("t2",background="blue")

Regards,
Matt



More information about the Python-list mailing list