Tkinter ListBox Item Count
The Tkinter ListBox size() method lists the number of options.
Tkinter ListBox Item Count Example#1
Create a ListBox and then list the number of items in the ListBox.
from tkinter import *
fruits = [
"Banana","Watermelon","Pineapple",
"Orange","Grapes","Mango"
]
root = Tk()
root.title("apidemos.com")
root.geometry("300x210")
lb = Listbox(root,selectmode=EXTENDED)
for fruit in fruits:
lb.insert(END,fruit)
lb.pack(pady=10)
print("items count:",lb.size()) # List the number of items
root.mainloop()
Output:
The following is the result of the execution in the Python Shell window.