Twhite1195
Twhite1195

Reputation: 351

tkinter listbox display problems

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

Answers (1)

TigerhawkT3
TigerhawkT3

Reputation: 49320

According to Effbot, you have to insert each item separately, rather than inserting 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

Related Questions