Python Forum

Full Version: A beginner with tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so basically I'm trying to display a list of labels inside of a labelframe, I tried to do it using a for loop and I got some weird results and wanted some help, Here's the code with some documentation
        i = 0
        for element in listoftups:  # it should do it for every element in a list of tuples
            if i < 20:
                ttk.Label(location
                          , text=element[0] + ' : ' + str(element[1])).grid(row=int(i)
                          , column=0)
# the location is the labelframe and the text is what I need in the labels
it like just prints the labels on top of each other and it's so weird and I have no idea why it wont go down in the rows
You don't increment i so row and column remain the same. Please don't use i. l. or O as single digit variable names as they can look like numbers. An alternative way using enumerate
for ctr, element in enumerate(listoftups): # it should do it for every element in a list of tuples
    if ctr < 20:
        ttk.Label(location, text=element[0] + ' : ' + str(element[1])
                 ).grid(row=ctr, column=0) # the location is the labelframe and the text is what I need in the labels