Akascape / CTkListbox

A simple listbox for customtkinter (extenstion/add-on)
MIT License
153 stars 13 forks source link

Highlight listbox item without selecting #15

Closed codedreamin closed 1 year ago

codedreamin commented 1 year ago

Is there a method to highlight listbox items without using select?

Something like CTkListbox.highlight(index)

To clarify I'm basically looking for a method to highlight listbox items without calling any command that's assigned to the listbox.

Akascape commented 1 year ago

@codedreamin Ok I will add this function.

For now use this:

listbox.buttons[index].configure(fg_color=listbox.select_color, hover=False)
codedreamin commented 1 year ago

@Akascape

Would highlighted listbox items still be found with a curselection call? My original comment may not have been clear, what I'm trying to do is select listbox items without calling the command assigned to the listbox

In that case I wonder if it might be easier to just add an option to the select method for choosing to call the command or not.

Thank you!

Akascape commented 1 year ago

@codedreamin Not with that method. But instead you can use this trick:

listbox = CTkListbox(root)
...
listbox.select(1) 
listbox.configure(command=func) # add the command after selecting
codedreamin commented 1 year ago

@Akascape

Yes I think that could work if the selections only happened once, unfortunately my list is dynamic. It's a list of curves that could be added to a graph. I have another list of 'saved graphs' and so essentially when a saved graph is selected it goes and selects the curves that were saved under that graph.

Akascape commented 1 year ago

@codedreamin Then you can set the command to none before selecting, then again set the function after selection.

listbox.configure(command=None)
listbox.select(1)
listbox.configure(command=func)
codedreamin commented 1 year ago

@Akascape

Ahh that could work, I'll give it a try. Thanks!

Edit: Works great!