Tkinter 通过双击删除 ListBoxvalues
Tkinter remove ListBoxvalues by double clicking
我想通过双击从 ListBox
中删除一个值。
我不明白如何使用 Tkinter 事件
获取 ListBox
项目的值
这是我到目前为止所做的:
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()
这就是你想要的。
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()
我想通过双击从 ListBox
中删除一个值。
我不明白如何使用 Tkinter 事件
ListBox
项目的值
这是我到目前为止所做的:
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()
这就是你想要的。
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()