.curselections
returns an empty tuple if nothing is selected. You are trying to get the user-selected input even before the user selects anything.
one way to overcome this is to set the default selection to the first row using .selection_set(0)
...
l=tk.Listbox(master=plc,listvariable=choicesvar)
l.pack()
l.selection_set(0)
print(l.get(l.curselection()))
...
But since you want to get user selected row, bind the <ButtonRelease>
to an event handler then get the selected rows. something as shown below.
import tkinter as tk
def handler(event):
print([l.get(index) for index in l.curselection()])
plc=tk.Tk()
choices=["A","B","C"]
choicesvar=tk.StringVar(value=choices)
l=tk.Listbox(master=plc,listvariable=choicesvar, selectmode=tk.MULTIPLE)
l.pack()
l.bind('<ButtonRelease>', handler)
plc.mainloop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…