Created
June 16, 2017 17:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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