Closed derrickcodez closed 1 year ago
Hi,
I have just managed how to do what this issue is looking for...
I know this is not encapsulated at first instance, for it will work for now.
def display_clientes(self):
listbox = CTkListbox(self, command=lambda x: print(x), text_color="#000", listvariable=listvariable)
listbox.bind("<Down>", lambda event: self.entry_on_keyup_keydown(listbox, 1))
listbox.bind("<Up>", lambda event: self.entry_on_keyup_keydown(listbox, -1))
listbox.grid(row=1, column=0)
def on_keyup_keydown(self, widget, direction):
current_index = widget.curselection()
next_index = (current_index + direction) % widget.size()
widget.activate(next_index)
Hope that helps.
Note: this only will work with no multiselection
@SilasPDJ
Thanks for your help—I'll definitely incorporate this as a feature. However, my main concern revolves around the functionality of swapping options in the listbox. Specifically, I want the ability to select an option, click the 'Move Up' button, and have the selected option move upward in the list.
Hi @derrickcodez ,
I've created a pull request #18 that introduces two new methods to address the reported issue. The new methods, move_up and move_down, provide a more optimized solution. Please review and let me know your thoughts or if any further adjustments are needed.
Thanks!
Please @derrickcodez, take a look at this issue about the scrollbar right here: https://github.com/Akascape/CTkListbox/pull/18#issuecomment-1744121023
@CheemaOTB, your solution worked perfectly, huge thanks! And kudos to @SilasPDJ for the arrow keys feature, super useful!
Hi,
When moving options in a listbox up and down it seems to glitch out (I think its related to something in the insert method). The code below works in tkinter but not Ctk.