Reputation: 3829
I want to remove a value from my ListBox
by double clicking.
I don't understand how can I get the value of the ListBox
item with the Tkinter Event
Here is what I've done so far :
import tkinter as tk
def addValuesListBox(listbox):
for i in range(10):
listbox.insert(tk.END, i)
def removeValue(event):
#here i'd like to remove the value to the corresponding listbox value
print("remove value")
if __name__ == '__main__':
window = tk.Tk()
listbox = tk.Listbox(window)
addValuesListBox(listbox)
listbox.bind( "<Double-Button-1>" , removeValue )
listbox.pack()
window.mainloop()
Upvotes: 1
Views: 277
Reputation: 62
This is what you want.
import tkinter as tk
def addValuesListBox(listbox):
for i in range(10):
listbox.insert(tk.END, i)
def removeValue(event):
selection = listbox.curselection()
print(selection)
listbox.delete(selection)
print("remove value")
if __name__ == '__main__':
window = tk.Tk()
listbox = tk.Listbox(window)
addValuesListBox(listbox)
listbox.bind( "<Double-Button-1>" , removeValue )
listbox.pack()
window.mainloop()
Upvotes: 2