i need to find and highlight with color OR bold specific words in string.
i thought on doing like this
word to put in red=is:
var="my string is that should is appear with the word flame is in red is"
varf=var.replace(" is ","\033[1;32;40m is ")
but this dont work on tkinter ScrolledText, just in terminal :s
is there a way to do this in a tkinter ScrolledText widget?
Word will appear in diferent places in string so its hard to do the config.tag because i have to specify the interval of characters in the string to color.
my code
def checkval(e, spec0, spec1, spec2, spec3, spec4, spec5):
e.widget.insert("1.0", PLACEHOLDER if e.widget.get("1.0", "end-1c") == "" else "")
reqlidst=(spec0, spec1, spec2, spec3, spec4, spec5)
textlabl=""
for x in reqlidst:
if len(x)>1:
#print("selected text: '%s'" % e.widget.get(SEL_FIRST, SEL_LAST))
if x.upper() in e.widget.get("1.0", "end-1c").upper():
if len(textlabl)>1:
textlabl = textlabl + "- " + x.replace(" ", "").upper() + " " + html.unescape('✔')+"\n\n"
else:
textlabl = "- " + x.replace(" ", "").upper() + " " + html.unescape('✔')+"\n\n"
else:
if len(textlabl) > 1:
textlabl =textlabl + "- " + x.replace(" ", "").lower() + " " + html.unescape('✘')+"\n\n"
else:
textlabl = "- " + x.replace(" ", "").lower() + " " + html.unescape('✘')+"\n\n"
e.widget.my_var_expected.set(textlabl)
reqlidst are the word to search for and show in red
How to change the color of certain words in the tkinter text widget? doesnt answer my question :/