在TkMessageBox中显示数组的元素

时间:2016-05-11 13:01:16

标签: python python-2.7

我使用的代码如下:

$pdfFilePath = base_url()."uploads/files/ash.pdf";

现在,我希望在显示MessageBox时发布if len(areUnusedParams) > 0: tkMessageBox.showinfo('Error!','The following parameters are unchanged throughout the C-files and are also not present in parameter.txt:\n') (这是一个数组)的内容,并且每个元素都应该在各自的行上。 我正在考虑这样的事情:

areUnusedParams

但我不知道如何实现它,PyCharm在我尝试的时候一直在抱怨。

1 个答案:

答案 0 :(得分:0)

当您将showinfo的areUnusedParams列表添加为第三个参数时,它将引发TypeError,如下所示:

Traceback (most recent call last):
  File ".../test.py", line 3, in <module>
    tkMessagebox.showinfo("title","message","thing")
TypeError: showinfo() takes from 0 to 2 positional arguments but 3 were given

由于您希望'\n'.join(areUnusedParams)成为消息的一部分,您需要将其添加到消息中,而不是作为附加参数传递:

tkMessageBox.showinfo('Error!',
                      'The following parameters are unchanged throughout the C-files and are also not present in parameter.txt:\n' \
                         + '\n'.join(areUnusedParams))

我假设所有areUnusedParams都是字符串,但只是要彻底,如果不是那么传递给str.join是无效的,在这种情况下你可以将它们全部转换为使用map的字符串:

'\n'.join(map(str,areUnusedParams))