Pharo Smalltalk: Reading from TextMorph

拟墨画扇 提交于 2019-12-23 19:08:19

问题


In Smalltalk using Pharo, I'm creating an application that reads the user input and does X.

So far I've managed to make a TextMorph that a user could enter a value into, but I'm unsure of how to read from TextMorphs and then do something with the value.

Any ideas?

Thanks


回答1:


Well, you can simply send text to your morph and get it's contents. So you could have a button and when button is pressed you do something with contents:

input := TextMorph new.
button :=
   SimpleButtonMorph new
      target: self
      actionSelector: #processTextMorph:;
      arguments: {input};
      yourself.

processTextMorph: aTextMorph
   | contents |
   contents := aTextMorph text.
   "do something with contents"

However maybe you want to use a dialog? Because you can do:

response := UIManager default request: 'What do you want to do?'.
response ifNotNil: [ "do something with the response" ]

And then the execution of UIManager default request: '…' will open a dialog with a text input



来源:https://stackoverflow.com/questions/39912260/pharo-smalltalk-reading-from-textmorph

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