Akascape / CTkListbox

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

Bug when I want to remove an option from the list #7

Closed ZachVFXX closed 11 months ago

ZachVFXX commented 11 months ago

When i use the listbox.delete(index) it leaves me with an error keyerror: and the index I'm trying to delete

this my code

`def ModifyDataWindow(button_name): window = ctk.CTkToplevel() window.geometry("400x600") window.title("Add data") font = ctk.CTkFont("Arial", 30)

label = ctk.CTkLabel(window, text=f"Modify {button_name} data", font=font)
label.pack(padx=20, pady=20)

data = read_values_from_json(FILE_PATH, button_name)

def show_value(selected_option):
    print(selected_option)

def remove_selection():
    selected_indices = listbox.curselection()
    for index in reversed(selected_indices):
        listbox.delete(index + 1)

listbox = CTkListbox(window, command=show_value, multiple_selection=True)
listbox.pack(fill="both", expand=True, padx=10, pady=10)

for item in data:
    listbox.insert(ctk.END, item)

removebutton = ctk.CTkButton(window, text="Remove", command=remove_selection)
removebutton.pack(padx=20, pady=20)`

Thank you for your help

Akascape commented 11 months ago

@ZachVFXX Fixed! update to the latest version.