Jadon Erwin
Jadon Erwin

Reputation: 661

Is there anyway to change the color of the highlighted text in a tkinter listbox?

I am trying to change the text color of a highlighted item in a Tkinter listbox and I can't find anything in the documentation for changing the text color. It seems like it is defaulted to a white text, and I would like it to stay the same color as depicted in my picture below. Also, bonus question: is it possible to not have the highlighted text underscored?

enter image description here

Thanks in advance!!!

Upvotes: 1

Views: 3770

Answers (1)

hgazibara
hgazibara

Reputation: 1832

Both is possible. You can set the selectforeground of the listbox widget to change its color and set the value of activestyle to remove the underline.

Here is an example from effbot page, augmented with foreground color definition and without item underline:

from tkinter import *

master = Tk()

listbox = Listbox(master, selectforeground='Black', activestyle='none')
listbox.pack()

listbox.insert(END, "a list entry")

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

mainloop()

Upvotes: 3

Related Questions