有没有一种简单的方法可以让它发挥作用?
text = "";
DialogInput[{TextCell["Try to type a text with linebreaks :-)"],
InputField[Dynamic[text], String],
Button["Ok", DialogReturn[text]]}]
问题是 InputField 在输入
Return
后终止.我只想要一个简单的文本输入字段。
最佳答案
感谢列昂尼德的提醒。这是代码:
text = "";
DialogInput[{TextCell["Try to type a text with linebreaks :-)"],
InputField[Dynamic[text], String, FieldSize -> {30, 6}],
DefaultButton[DialogReturn[text]]},
NotebookEventActions -> {"ReturnKeyDown" :>
FrontEndExecute[NotebookWrite[InputNotebook[], "\n"]]}]
FrontEndExecute 语句在此版本中稍微简单一些。
顺便说一句,要清除 NotebookEventActions 的默认 Return 键操作,您可以使用
NotebookEventActions->{}
.这对于阻止对话框在输入过程中消失很有用。
关于user-interface - 接受换行符的简单文本输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6946475/