Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda