Python Forum
A beginner with tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A beginner with tkinter
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner question re: Tkinter geometry return2sender 3 958 Jun-19-2023, 06:19 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020