Akascape / CTkListbox

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

Error when deleting all in empty listbox #60

Open ShawezA opened 2 months ago

ShawezA commented 2 months ago

If you try to delete an empty listbox using listbox.delete("all", tkinter.END) you get this error: line 178, in deselect
if self.buttons[index] in self.selections:


KeyError: 0
ShawezA commented 2 months ago

I was able to fix it by changing the deselect function: def deselect(self, index): if not self.multiple: if self.selected: self.selected.configure(fg_color=self.button_fg_color) self.selected = None return if index in self.buttons and self.buttons[index] in self.selections: self.selections.remove(self.buttons[index]) self.buttons[index].configure(fg_color=self.button_fg_color)

jipen commented 1 month ago

Prettier printed (BTW I also struggle with the GitHub editor ! ;)):

def deselect(self, index): 
    if not self.multiple: 
        if self.selected: 
           self.selected.configure(fg_color=self.button_fg_color) 
           self.selected = None 
           return 
    if index in self.buttons and self.buttons[index] in self.selections: 
       self.selections.remove(self.buttons[index]) 
       self.buttons[index].configure(fg_color=self.button_fg_color) 

Tested and approved !