Skip to content

Instantly share code, notes, and snippets.

@uuklanger
Created June 16, 2017 17:01
Show Gist options
  • Save uuklanger/3c0740341fe7c39fdbec219472dc2c3e to your computer and use it in GitHub Desktop.
Save uuklanger/3c0740341fe7c39fdbec219472dc2c3e to your computer and use it in GitHub Desktop.
Sample code that shows how to use multiple colors within a Text TK box. This is in the form of a console
from tkinter import *
root = Tk()
text = Text(root, wrap=NONE, bg="black", fg="lightgreen", font=("Consolas", 10, "normal"))
BG_EVEN = 'BG_EVEN'
BG_ODD = 'BG_ODD'
text.tag_config('FG_FATAL', foreground='yellow', background='red')
text.tag_config('FG_ERROR', foreground='orange')
text.tag_config('FG_WARN', foreground='yellow')
text.tag_config(BG_EVEN, background='#2A2A2A')
text.tag_config(BG_ODD, background='#000000')
text.pack()
for x in range(1,3,1):
if (x % 2) == 0:
BG_CUR = BG_EVEN
else:
BG_CUR = BG_ODD
text.insert(END, 'NORMAL Text %s\n' % BG_CUR, (BG_CUR))
for x in range(1,3,1):
if (x % 2) == 0:
BG_CUR = BG_EVEN
else:
BG_CUR = BG_ODD
text.insert(END, 'WARNING Text %s\n' % BG_CUR, (BG_CUR,'FG_WARN'))
for x in range(1,3,1):
if (x % 2) == 0:
BG_CUR = BG_EVEN
else:
BG_CUR = BG_ODD
text.insert(END, 'ERROR Text %s\n' % BG_CUR, (BG_CUR,'FG_ERROR'))
for x in range(1,3,1):
if (x % 2) == 0:
BG_CUR = BG_EVEN
else:
BG_CUR = BG_ODD
text.insert(END, 'FATAL Text %s\n' % BG_CUR, ('FG_FATAL'))
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment