Simple text input field accepting line breaks

倾然丶 夕夏残阳落幕 提交于 2019-12-09 10:09:08

问题


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]]}]

The problem is that InputField terminates after typing Return. I just want a simple text input field.


回答1:


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"]]}]

The FrontEndExecute statement is a little simpler in this version.

Incidentally, to clear the default Return key action of NotebookEventActions you can use NotebookEventActions->{}. This can be useful to stop dialogs disappearing during input.



来源:https://stackoverflow.com/questions/6946475/simple-text-input-field-accepting-line-breaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!