For example:
import tkinter as tk
x = tk.Tk()
y = tk.Listbox(x, bg="white")
y.insert(tk.END, "value1")
y.insert(tk.END, "value2")
>>>return y.index("value1")
This should output 0 but it just gives me an error, I did some reasearch and I can't find anything that has so I ask here.
The index
method of the listbox isn't the same as the index
method of a python list. For the listbox, it translates something like "end" or "@x,y" into a numerical index.
To search, get the values as a python list, and then use the index
method of the list:
index = y.get(0, "end").index("value1")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With