import sys

from Tkinter import *

from ScrolledText import ScrolledText

TK = Tk()

# Create the (scrolled) text wodget; insert some lines of text


textW = ScrolledText(TK, height=3, width=30, background='gray60',

					 font='courier 14')

textW.pack(expand=1, fill=BOTH)

textW.insert('0.0', 'line 1\nline 2\nline 3\nline 4\nQUIT\n')

# Create several `tags' with various color and relief properties.


textW.tag_config('tag1', foreground='blue')

textW.tag_config('tag2', background='palegreen',

				 relief=RAISED, borderwidth=1)

textW.tag_config('tag3', foreground='white', background='red',

				 font='courier 16 bold',

				 relief=RAISED, borderwidth=2)

# Bind a callback to `tag3'


textW.tag_bind('tag3', '<1>', sys.exit)

# Assign tags to various regions of the text


textW.tag_add('tag1', '1.0', '2.0')

textW.tag_add('tag2', '2.0', '3.0')

textW.tag_add('tag1', '3.0', '3.6')

textW.tag_add('tag2', '3.5', '3.6')

textW.tag_add('tag3', '5.0', '5.6')

TK.title('Text Example')

TK.mainloop()