在使用Pharo的Smalltalk中,我创build了一个读取用户input和X的应用程序。
到目前为止,我设法使一个TextMorph,用户可以input一个值,但我不确定如何从TextMorphs读取,然后做一些值。
有任何想法吗?
谢谢
那么,你可以简单地发送text
到你的变形,并得到它的内容。 所以你可以有一个按钮,当按下按钮时,你用内容做一些事情:
input := TextMorph new. button := SimpleButtonMorph new target: self actionSelector: #processTextMorph:; arguments: {input}; yourself. processTextMorph: aTextMorph | contents | contents := aTextMorph text. "do something with contents"
但是,也许你想使用对话框? 因为你可以这样做:
response := UIManager default request: 'What do you want to do?'. response ifNotNil: [ "do something with the response" ]
然后执行UIManager default request: '…'
将打开一个带有文本输入的对话框