Akascape/CTkListbox

<<ListboxSelect>> event binding not compatible

seandomal opened this issue · 4 comments

I have a python gui where I need to keep track of the order in which I select things in the listbox. In order to do this using normal tkinter you have to bind the <> event to the listbox and basically dump the indicies into a list to keep track of the order. Is it possible to either make the <> event binding compatible or add some way to keep track of the order of item selection in the listbox?

To get this to work in tkinter I do the following:

    # Setting up the listbox
    self.listbox = Listbox(root, selectmode=MULTIPLE)
    self.listbox.pack(pady=10, fill="both", expand=True)
    # Bind the selection event
    self.listbox.bind('<<ListboxSelect>>', self.on_listbox_select)
    
    
    def on_listbox_select(self, event=None):
    # Get currently selected items
    current_selection = set(self.listbox.curselection())
    # Determine the new selection (if any)
    new_selection = current_selection - set(self.selection_order)
    # Determine deselected items (if any)
    deselected = set(self.selection_order) - current_selection
    # Remove deselected items from the order list
    self.selection_order = [item for item in self.selection_order if item not in deselected]
    # Add the new selection to the order list
    self.selection_order.extend(new_selection)
    # Debug: Print the order of selection
    print("Selection Order:", [self.listbox.get(i) for i in self.selection_order])

@seandomal I will implement it tomorrow, sorry I am busy right now.

@seandomal I will implement it tomorrow, sorry I am busy right now.

Sounds great, thank you so much!

@seandomal Added the suggestion. Update to the latest version!