color of listbox entries (Tkinter)

Thomas Thiele thiele at muc.das-werk.de
Wed Jun 7 12:34:19 EDT 2000


Hallo!

I want to show entries in a listbox with different (foreground)-color.
For example, the first entry is red, the second green, the third blue
and so on.


entrylist = ["one", "two", "three", "four"]
color = 0
for entry in entrylist:	
	if color==0: 
		self.Listbox["foreground"] = "#f00"	#red
	else: 
		self.Listbox["foreground"] = "#0f0"	#green
	self.Listbox.insert("end", entry)
	if color == 0: color = 1
	else: color = 0

In this example all odd numbers shall be red and all even numbers green.
But this doesn't work. (all entries are green)

Has anyboby an idea how this can be realized?
I want to have "clickable"-Widgets. -> Labels cannot be used.

Thanks Thomas



More information about the Python-list mailing list