Closed odavidsons closed 1 year ago
The example code i was experimenting with
import customtkinter as ctk
import tkinter as tk
from CTkListbox import *
def callback(event):
selection = event.widget.curselection()
if selection:
index = selection[0]
data = event.widget.get(index)
print(data)
def ctkcallback(selected):
print(selected)
app = tk.Tk()
ctk.set_appearance_mode("dark")
frame = ctk.CTkFrame(app)
frame.grid()
listbox = tk.Listbox(frame)
listbox.insert(tk.END,"teste1")
listbox.insert(tk.END,"teste2")
listbox.bind("<<ListboxSelect>>", callback)
listbox.grid(row=0,column=0)
ctklistbox = CTkListbox(frame,command=ctkcallback)
ctklistbox.insert("END","teste1")
ctklistbox.insert("END","teste2")
ctklistbox.grid(row=0,column=1)
app.mainloop()
@odavidsons Ok, I figured it out, the problem is with "End" index.
Oh yeah, i see. Well, that is kind of an issue since i needed to dynamically add items to the last index of the list. Guess a workaround would need to be thought of for that
@odavidsons Ok, its fixed now. You can now bind it like this: listbox.bind("<1>", func)
The END method bug is also fixed.
Awesome! Thanks for the quick answer.
Hello! I've been using this addon alongside with CTK and i just stumbled apon some behaviour issues while trying to get callbacks when a list item is selected.
1 - While trying to bind a selection event ("listbox.bind("<>", callback)") it simply does not run.
2 - If i use the "command=" argument while declaring the listbox and point it to a function, i am able to get the selected item but only for the first time. After selecting an item for the second time the list refuses to visually change (and the selection actually remains stuck) and it only returns the last indexed item.
I did test the normal tkinter listbox and all is working as intended.
It could be incorrect implementation on my part, but some feedback on this would be aprecciated!