2011-03-18 9 views

Respuesta

18

De acuerdo con la documentación effbot.org respecto el widget Listbox no se puede cambiar el color de los elementos spefic:

El cuadro de lista sólo puede contener elementos de texto, y todos los artículos deben tener el mismo tipo de letra y color

Pero en realidad puede cambiar tanto la fuente como los colores de fondo de elementos específicos, utilizando el método itemconfig de su objeto Listbox. Vea el siguiente ejemplo:

import tkinter as tk 


def demo(master): 
    listbox = tk.Listbox(master) 
    listbox.pack(expand=1, fill="both") 

    # inserting some items 
    listbox.insert("end", "A list item") 

    for item in ["one", "two", "three", "four"]: 
     listbox.insert("end", item) 

    # this changes the background colour of the 2nd item 
    listbox.itemconfig(1, {'bg':'red'}) 

    # this changes the font color of the 4th item 
    listbox.itemconfig(3, {'fg': 'blue'}) 

    # another way to pass the colour 
    listbox.itemconfig(2, bg='green') 
    listbox.itemconfig(0, foreground="purple") 


if __name__ == "__main__": 
    root = tk.Tk() 
    demo(root) 
    root.mainloop() 
+0

ahhh ... bien, gracias. Soy nuevo en Python y estaba tratando de usar .configure (bg = "Green") –

Cuestiones relacionadas