Tkinter Listbox

Joseph A Knapka jknapka at earthlink.net
Fri Aug 9 18:31:56 EDT 2002


Matthias Huening wrote:
> 
> Hi,
> 
> Is it possible to change the color (background and/or foreground)
> of some of the entries of a listbox?
> 
> Thanks, Matthias

from Tkinter import *
root = Tk()
l = Listbox(root)
l.pack()
l.insert('end',"Hello")
l.itemconfig(0,bg='blue')
l.itemconfig(0,fg='red')

That works on Python 2.2. Older versions (pre-2.1, maybe?)
didn't implement itemconfig for listboxes. That's easily
fixed by editing Tkinter.py and copying the definition
of the itemconfig method from Canvas to Listbox, IIRC.

Cheers,

-- Joe



More information about the Python-list mailing list