Akascape / CTkListbox

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

.delete not working? Maybe? #13

Closed Mariuseledy closed 1 year ago

Mariuseledy commented 1 year ago

Hey, I'm trying to delete all the data inside my listbox every time I search and add the new data that matches some characters (basically a search box). When I'm trying to delete the data I keep getting this error:

File "C:\Users\Mariusel\Desktop\New folder (2)\main.py", line 142, in update_listbox(people_list_from_db) File "C:\Users\Mariusel\Desktop\New folder (2)\main.py", line 137, in update_listbox listbox.delete(customtkinter.END, 0) TypeError: CTkListbox.delete() takes 2 positional arguments but 3 were given

This is my code: def update_listbox(data):

Sort the data alphabetically by the "nume" field

sorted_data = sorted(data, key=lambda x: x["nume"].lower())
listbox.delete(customtkinter.END, 0)
for person in sorted_data:
    listbox.insert(customtkinter.END, person["nume"])

The code was working before and it was the same except the customtkinter.END syntax. Can I get some help with that?

Mariuseledy commented 1 year ago

Nevermind I just had to do listbox.delete("all") and it works now.

codedreamin commented 1 year ago

@Mariuseledy

Thanks for this, in CtkListbox V0.4 I had been deleting all items in the listbox with this method

for d in range(self.leaching_schedules.size()): self.leaching_schedules.delete(d)

When updating to V0.8 it suddenly started having an index error. Using listbox.delete("all") fixed it.

Akascape commented 1 year ago

@Mariuseledy @codedreamin I tried to fix this issue, please try the new version.

codedreamin commented 1 year ago

@Akascape

It seems to be fixed now. Thank you!