This is 3rd part of the Listbox videos. In previous 2 video we have seen how we can create and select the items in different way. In this video you'll learn how we can get the selected item and use into our program and along with that we will also show how you can delete a selected item.
example code (in video)-
from tkinter import *
def print_me():
clicked_items = l.curselection()
print(clicked_items)
for item in clicked_items:
print(l.get(item))
def delete_me():
clicked_items = l.curselection()
for item in clicked_items:
print(l.delete(item))
root = Tk()
l = Listbox(root, width=30, height=15, selectmode= SINGLE)
l.insert(1, "C++")
l.insert(2, "C#")
l.insert(3, "Python")
l.insert(4, "Java")
l.insert(5, "Javascript")
l.pack()
button = Button(root, text="print", command=print_me)
button.pack()
button_delete = Button(root, text="delete", command=delete_me).pack()
root.geometry("400x400+120+120")
root.mainloop()
--------------------------------
So i am sure your queries like -
- How we can get selected items in Tkinter Listbox?
- how we can fetch selected items from Listbox in TKinter?
- How we can delete selected items in Tkinter Listbox?
- How we can delete items in tkinter Listbox?
have been solved.
So guys this is all for today, if you have any type of confusion in Listbox or in any part of this series. Then feel free to comment or contact us on facebook-
Facebook - https://facebook.com/programmingcage