Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
Is there a way to correctly show tag borders in tkinter?

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: |my example|

What I get: |my |example|

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda