Pharo Smalltalk:从 TextMorph 读取 [英] Pharo Smalltalk: Reading from TextMorph
问题描述
在使用 Pharo 的 Smalltalk 中,我正在创建一个读取用户输入并执行 X 的应用程序.
In Smalltalk using Pharo, I'm creating an application that reads the user input and does X.
到目前为止,我已经设法制作了一个用户可以输入值的 TextMorph,但我不确定如何从 TextMorphs 读取数据,然后对值进行处理.
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.
有什么想法吗?
谢谢
推荐答案
好吧,您可以简单地将 text
发送到您的变形并获取其内容.所以你可以有一个按钮,当你按下按钮时,你可以对内容做一些事情:
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" ]
然后执行UIManager default request: '...'
将打开一个带有文本输入的对话框
And then the execution of UIManager default request: '…'
will open a dialog with a text input
这篇关于Pharo Smalltalk:从 TextMorph 读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!