herrkami
herrkami

Reputation: 13

Tkinter.Listbox(): Active line without change of color?

I'm using the Tkinter.Listbox() widget (in python) to create a list of possible colors to select:

import Tkinter as tk

color_palette =    ['#FF4D00',
                    '#00A1C3',
                    '#89F055',
                    '#F943A8',
                    '#534569']
_root = tk.Tk()
_col_pick = tk.Listbox(_root, height=4, width=10, activestyle='dotbox')
_col_pick.pack()
for i, c in enumerate(color_palette):
    _col_pick.insert(tk.END, c)
    _col_pick.itemconfig(i, {'bg':c})
_root.mainloop()

Quite obviously, I don't want Tk to override the selected line color by a default color, when active (i.e. selected by the cursor). Unfortunately, this is what happens, even when I set activestyle='none'. Is there a way to disable this color change when selecting a line? Greatest solution for me would simply be a dotted outline without any filling. Thanks,

Kami

Upvotes: 0

Views: 1103

Answers (1)

MrAlexBailey
MrAlexBailey

Reputation: 5289

You can add selectbackground to your insert() loop:

for i, c in enumerate(color_palette):
    _col_pick.insert(tk.END, c)
    _col_pick.itemconfig(i, {'bg':c, 'selectbackground':c})

This will set the background of the selection to the same color.

Upvotes: 1

Related Questions