I am working on a text markup tool using tkinter. It is mostly built around using various tag methods on the Text widget. The thing that is driving me crazy, however, is my inability to get correct borders around tagged text if there are overlapping tags.
Consider the following piece of text, tagged with two different tags shown with square brackets:
[my [example]]
When I use .tag_configure("outer", borderwidth=1, relief="solid"), I want to get a border around "my example", however, I get two borders: around "my " and around "example" if the background color is set for "example". If there is no background color involved, it works as I want. But I really need the ability to change background colors!
Minimal working example:
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.grid(row=0, column=0, sticky=tk.N+tk.S+tk.W+tk.S)
self.text = tk.Text(self)
self.text.insert("1.0", "my example")
self.text.tag_add("outer", "1.0", "end-1c") # "my example"
self.text.tag_configure("outer", borderwidth=1, relief="solid")
self.text.tag_add("inner", "1.3", "end-1c") # "example"
self.text.tag_configure("inner", background="white") # white to see the problem better
self.text.grid(row=0, column=0)
if __name__ == "__main__":
root = tk.Tk()
app = Application(root)
app.mainloop()
Question: is there a way (possibly hacky) to get single borders around such "outer" tags?
What I want: 
What I get: 
The only solution I know is to embed another Text with a border in the main Text using Text.window_create() and configure its tags for inner colors.