0

I have a problem with the listbox because it does not display names like in the first listbox under 1T, only on one line, I want to display the names one under the other. I have no idea how to do this. Thank you for every advice and attention to the code below

enter image description here

import random
import tkinter, sys
from tkinter import *
import tkinter.messagebox as messagebox

los = []
list = ['1. Kamil Winnicki', '#2. Wiktor Jasiński', '3. Adam Turowski', '#4. Arek Major', '5. Dominik Piechotka', '#6. Jakub Laskowski', '7. Jakub Materak', '8. Kacper Kołodziejski',
        '#9. Kamil Stankiewicz', '10. Konrad Nosek', '11. Krzysiek Wawszczak', '12. Andrzej Oleksiak', '13. Miłosz Tarucin', '14. Paweł Pawłowski', '#15. Mateusz Lebioda']
lines = list

for line in lines:
    if line [0] != '#':
        los.append(line)

main = tkinter.Tk()

def koniec():
    main.destroy()

def losowanie():
    messagebox.showinfo(message=random.sample(los ,1))

#nagłowek
te = tkinter.Label(main, text = 'Lista 1T:')
te.pack()

#Wyswietla liste 1T
listbox = Listbox(main, width=21, height=15)
listbox.insert(1, '1. Mateusz Lebioda', '2. Jakub Laskowski', '3. Kamil Winnicki', '4. Wiktor Jasiński', '5. Adam Turowski', '6. Arek Major', '7. Dominik Piechotka', '8. Jakub Materak', '9. Kacper Kołodziejski', '10. Kamil Stankiewicz', '11. Konrad Nosek', '12. Krzysiek Wawszczak', '13. Andrzej Oleksiak', '14. Miłosz Tarucin', '15. Paweł Pawłowski')
listbox.pack()

#Obecne osoby
obecne1 = tkinter.Label(main, text = 'Obecne osoby:')
obecne1.pack()

obecne = Listbox(main)
obecne.insert(1, los)
obecne.pack()



#losuje
y = tkinter.Button(main, text = 'losuj', command = losowanie)
y.pack()


#wyjscie z aplikacji
x = tkinter.Button(main, text = 'Zakoncz', command = koniec)
x.pack()

main.mainloop()

1 Answer 1

2

You need to unpack your list when inserting.

Changing insertion line would be enough.

obecne.insert("end", *los)
                    #^ notice this star here. That one makes the unpacking

or you can just iterate over your list items using for loop.

obecne = Listbox(main)
for item in los:
    obecne.insert("end", item)
obecne.pack()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.