Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when deleting all in empty listbox #60

Open
ShawezA opened this issue May 1, 2024 · 2 comments
Open

Error when deleting all in empty listbox #60

ShawezA opened this issue May 1, 2024 · 2 comments

Comments

@ShawezA
Copy link

ShawezA commented May 1, 2024

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
Copy link
Author

ShawezA commented May 1, 2024

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
Copy link

jipen commented May 7, 2024

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants