Reputation: 351
I've been trying to get a listbox to work, however, I've had no success at all. The box appears, and the data too... but all together. I have a list that looks something like this:
lst=["item1","\n","item2","\n","item3","\n"]
my listbox code looks somewhat like this:
s=""
for x in lst:
s+=str(x)
itemlist=Listbox(window)
itemlist.insert(0,s)
itemlist.place(x=100,y=120)
the problem is, when I run it, the listbox displays like a joinlist, something like this:
item1item2item3
is there a way to get the listbox to actually work in displaying each item like this:
item1
item2
item3
Upvotes: 0
Views: 686
Reputation: 49320
According to Effbot, you have to insert
each item separately, rather than insert
ing one large string. Using append
to build a list
works in a similar way.
lst=["item1","item2","item3"]
itemlist=Listbox(window)
for item in lst:
itemlist.insert(END,item)
itemlist.place(x=100,y=120)
Upvotes: 2