消息框消息中的Python-for

时间:2016-04-11 13:51:30

标签: python-3.x for-loop printing tkinter tkmessagebox

我有一个产品清单

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

我希望将它们显示在tkinter messagebox对象中,作为消息。 所以想要这样的东西:

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

但是如何将字符串输入作为消息输出产品列表中的所有元素? 这甚至可能吗?

我想知道你是否可以使用循环...

1 个答案:

答案 0 :(得分:0)

如果构建一个字符串是你的问题,是的,它是可能的,并且可以通过循环来完成。

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

变量st将具有您需要输入MessageBox的输出 (" \ n"是一个换行符,我们使用字符串连接来形成正确的输出字符串)