简体   繁体   English

如何通过 wxPython 在 messageBox 中使用 python 换行?

[英]How do I make a newline with python in a messageBox through wxPython?

"\n" doesn't work for me here, going to say that before anyone suggests it. "\n" 在这里对我不起作用,要在任何人建议之前说出来。

I am currently working on a dialog message, which works fine.我目前正在处理一条对话消息,效果很好。 It shows an OK button with an information icon.它显示一个带有信息图标的确定按钮。 In the dialog, (or messageBox), I am outputting an array of strings, but the issue is that these string don't start on a newline so the dialog looks a little messy.在对话框(或消息框)中,我正在输出一个字符串数组,但问题是这些字符串不是从换行符开始的,所以对话框看起来有点乱。 Here's an example:这是一个例子:

myArray = ["Bananas", "Apples", "Pears", "Mangos"]

def showMessagebox():
   gui.messageBox(myArray, "Juicy fruits", wx.ICON_INFORMATION)

the output then does: output 然后执行:

Bananas Apples Pears Mangos

Even when I put a "\n" before them, I also tried putting an "\n" after them.即使我在它们前面加上“\n”,我也尝试在它们后面加上一个“\n”。 it won't work: It is actually including the "n" within the string!它不起作用:它实际上是在字符串中包含“n”! Not what I want.不是我想要的。 What I actually want is:我真正想要的是:

Bananas
Apples
Pears
Mangos

Doing something like "\n bananas" or "bananas \n" doesn't work."\n bananas""bananas \n"这样的操作是行不通的。 I assume that's because it's a messageBox.我认为那是因为它是一个消息框。 I want to know what will work!我想知道什么会起作用! Help is greatly appreciated thank you =)非常感谢您的帮助,谢谢=)

For demonstration, here's a screenshot of the dialog为了演示,这里是对话框的截图在此处输入图像描述

You are passing in a list instead of a string.您正在传递一个列表而不是一个字符串。 Try尝试

gui.messageBox('\n'.join(myArray), "Juicy fruits", wx.ICON_INFORMATION)

instead.反而。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM