0

I currently have this code:

for element in tagall:  
    for item in element: 
       items = item
        print(item)  

but I can't seem to incorporate it into changing the text attribute on a label in tkinter. When I do:

label.config(text=(item))  

the label only displays the last item and not all of them.
Thanks in advance

P.S. I fogot to mention that I'm using an sql server and 'tagall' is a variable of which a column of data has been set to

2
  • What about something like: label.config(text='\n'.join(element)) Commented Feb 19, 2014 at 16:32
  • No, that still only displays the last item Commented Feb 19, 2014 at 16:40

2 Answers 2

1

Try this:

label.config(test=repr(tagall))

That should get you going down the right path

Sign up to request clarification or add additional context in comments.

3 Comments

This does not separate the fields onto their own line - it just displays them
I wasn't trying to format the response -- I was trying to help you with your bug "...the label only displays the last item and not all of them...". I assumed once you saw the output from repr() you'd figure out how to format the output appropriately.
newScreenLabel.config(text=("\n".join(str.split(repr(tagall))))) displays each value on a new line
1

Think about what label.config(text=(item)) does. When you call the function, it overwrites the existing text of label with the new text stored in item. Therefore, it shouldn't surprise you that you only see the last item.

Now, it depends on what you want the display of the list of items to look like. Do you want them each on their own line? Separated by spaces? That's going to determine the string you use to join the list of items.

If you want them separated by new lines, replace your loop with

label.config(text=("\n".join(list_of_items)))

Then you should be good to go.

3 Comments

TypeError: sequence item 0: expected str instance, pyodbc.Row found
Sorry, dropped the extra parens,label.config(text=("\n".join(list_of_items)))
Where does the parens go? EDIT: Added the parens around the list of items but this only separates the last field into its individual letters of individual lines

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.