I'm writing a small utility in Python that does some pattern matching of text. Text that matches the pattern the user has entered gets highlighted yellow. I'm achieving this using a Tkinter Text widget, and setting up a tag on the textbox named "match" that gives any text with the tag name "match" a yellow background. This all looks nice, except when I go to highlight the text using the mouse (e.g. when wanting to copy/paste). When I highlight the text with the mouse, any of the tagged text that already has a yellow background retains its yellow background, even after being highlighted. This means you can't properly read the text when it's been highlighted by the mouse, as the white text (text goes white when highlighted by mouse) on a yellow background provides bad contrast.
What I would like to happen is that when I highlight the text in the Text widget using the mouse, all of the text gets the standard blue background color/white text color that you'd normally get on a Windows machine when highlighting a section of text.
Here's a quick code snippet to demonstrate what I mean:
from Tkinter import *
root = Tk()
w = Text(root)
w.tag_config("match",background="yellow")
w.config(highlightbackground="red")
w.pack()
w.insert(INSERT,"some non-matching text.")
w.insert(INSERT,"some matching text.","match")
root.mainloop()
If you run this, and then highlight all of the text in the Text widget, you'll see that the text with the yellow background becomes very hard to read. Note that in the code snippet above I've tried changing the highlight background color using:
w.config(highlightbackground="red")
But this hasn't worked.