接受换行符的简单文本输入字段 [英] Simple text input field accepting line breaks
本文介绍了接受换行符的简单文本输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法可以让它发挥作用?
Is there a simple way to get this to work?
text = "";
DialogInput[{TextCell["Try to type a text with linebreaks :-)"],
InputField[Dynamic[text], String],
Button["Ok", DialogReturn[text]]}]
问题是 InputField 在输入 Return
后终止.我只想要一个简单的文本输入字段.
The problem is that InputField terminates after typing Return
. I just want a simple text input field.
推荐答案
感谢 Leonid 的提醒.代码如下:
Thanks for the heads-up Leonid. Here is the code:
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 语句在这个版本中稍微简单一些.
The FrontEndExecute statement is a little simpler in this version.
顺便说一下,要清除 NotebookEventActions 的默认 Return 键操作,您可以使用 NotebookEventActions->{}
.这对于阻止对话框在输入过程中消失很有用.
Incidentally, to clear the default Return key action of NotebookEventActions you can use NotebookEventActions->{}
. This can be useful to stop dialogs disappearing during input.
这篇关于接受换行符的简单文本输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文