Tkinter Listbox - Different Text colors in one listbox

Hendrik van Rooyen mail at microcorp.co.za
Thu May 31 02:48:48 EDT 2007


 <rfg007 at gmail.com> wrote:


> On May 29, 2:02 pm, rahulna... at yahoo.com wrote:
> > Hi,
> > Is it possible to havedifferentitems in alistboxindifferentcolors? Or is it
justonecolor for all items in alistbox?
> > Thanks
> > Rahul
>
> from Tkinter import *
>
> root = Tk()
> l = Listbox(root)
> l.pack()
> for x in range(10):
>     l.insert(END, x)
> l.itemconfig(2, bg='red', fg='white')
> l.itemconfig(4, bg='green', fg='white')
> l.itemconfig(5, bg='cyan', fg='white')
> root.mainloop()
>
> You can _only_ configurate 'background', 'foreground',
> 'selectbackground', 'selectforegroud', not font :(

Live and learn, - was not aware you could do this - thanks, nice one.

- Hendrik




More information about the Python-list mailing list