-1

I have a list of products

products = ["meat","salad","tomatoes"]

And I want to display them in a tkinter messagebox object, as the message. So want something like this:

This products are already in the list:
-meat
-salad
-tomatoes

But how can I put in the string to output as the message all the elements in the products list? Is that even possible?

I was woundering if you can use loops in this...

Steve
  • 73
  • 1
  • 1
  • 13
  • So, do you have an issue constructing a string or putting it into the MessageBox? – illright Apr 11 '16 at 14:05
  • Since I have to give a string to the messagebox widget, I was woundering if I could usa another method, instead of creating a string a part, and then putting it into the widget. – Steve Apr 11 '16 at 14:08

1 Answers1

0

If constructing a string is your issue, yes, it is possible and can be done with a loop.

st = "This products are already in the list:"
for i in products:
    st += "\n-" + i

The variable st will then have the output you need to put in a MessageBox.
("\n" is a newline character, we use string concatenation to form the correct output string)

illright
  • 3,991
  • 2
  • 29
  • 54
  • Yea I was just woundering if there was a method for doing this directly in the "command" field of the messagebox. – Steve Apr 11 '16 at 15:59