from tkinter import *
from random import randint

root = Tk()
try:
    root.option_readfile('lecture_options.txt')
except TclError:
    pass
root.title('tkinter Text Demo')

tagNamesAndAttrs = (
    # ( description, {
    #     [ attributeKeyword: attributeValue, ]*
    # } ),
    ( "normal text (no special tag attributes)", {
    } ),
    ( "12-point bold italic Verdana", {
        'font': ('Verdana', 12, 'bold', 'italic')
    } ),
    ( "24-point bold Verdana", {
        'font': ('Verdana', 24, 'bold')
    } ),
    ( "16-point Tempus Sans ITC in red", {
        'foreground':  'red',
        'font':        ('Tempus Sans ITC', 16),
    } ),
    ( "14-point Courier in green", {
        'foreground':  'dark green',
        'font':        ('Courier', 14),
    } ),
    ( "18-point Arial in blue", {
        'foreground':  'blue',
        'font':        ('Arial', 18),
    } ),
    ( "grooved with a border width of 4", {
        'relief':      GROOVE,
        'borderwidth': 4,
    } ),
    ( "grooved with a border width of 8 and a dark red background",  {
        'relief':      GROOVE,
        'background':  '#cc0000',
        'borderwidth': 8,
    } ),
)
nTags = len(tagNamesAndAttrs)

text = Text(root, height=nTags) # height is in lines (for Text) of "normal" text, I think
for i, (description, attrOfKwd) in enumerate(tagNamesAndAttrs):
    tagName = "_tag" + str(i)
    text.tag_configure(tagName, **attrOfKwd)
    text.insert(END, description + '\n', tagName)

if 0: # demonstrating another possible text.insert "index" syntax 
    text.insert("3.4", "This is on line 3, column 4")
    
text.grid(row=0, column=0)
root.mainloop()
