Home > Back-end >  How to avoid changing colour of selected text in tkinter when I highlight syntax with idlelib
How to avoid changing colour of selected text in tkinter when I highlight syntax with idlelib

Time:10-02

I have recently found out enter image description here

Actual Result (You can see that the selected text 't ("Hello Wor' is black but I don't want it to be black, I want it to be what it is):

enter image description here

So my aim is to NOT change the foreground colour of the selected text regardless of what colour it is tagged with. Thanks in advance.

CodePudding user response:

So OP is right. ColorDelegator calls self.tag_raise('sel') which puts the tag at the top so the foreground option of the "sel" tag is taken instead of the other tags.

If you do this:

import tkinter as tk

root = tk.Tk()
txt = tk.Text(root)
txt.pack()
print(txt.tag_config("sel")["foreground"]) # Outputs ('foreground', '', '', '', '#000000')

You can see that tkinter or tcl has set a default foreground option for the "sel" tag. To remove it use txt.tag_config("sel", foreground="").

  • Related