[Newbies] Just playin' around

Nicola Mingotti nmingotti at gmail.com
Tue Aug 13 20:55:26 UTC 2019


I am a beginner, like you, and I learnt how to bind buttons to actions 
from the Workspace a few days ago :)

So, here is a minimal working snippet. Run one line at a time for best 
fun. First line is only to clean already existing widgets. I did not put 
the Layout stuff to keep things as easy/nice as possible.

--------------------
"Run this line to clean up and restart testing. Not useful on first run "
s delete. bp delete. bm delete.

s := StringMorph new.
s openInWorld .
s contents: '0'.
s position: 100 at 100.

bp := SimpleButtonMorph new.
bp openInWorld .
bp label: 'Plus-1'.
bp position: 150 at 100.

bm := SimpleButtonMorph new.
bm openInWorld .
bm label: 'Minus-1'.
bm position: 250 at 100.

"------ Add actions to buttons ------------ "
bp target: [ s contents: (s contents asInteger + 1) asString ].
bp actionSelector: #value.

bm target: [ s contents: (s contents asInteger - 1) asString ].
bm actionSelector: #value.

--------------------

bye
Nicola





On 8/13/19 12:40 PM, Michael Rice wrote:
> A TextMorph (string '15') and two SimpleButtons, one with a '+' and 
> the other with a '-'.
>
> Target for both buttons is the TextMorph. The following, executed 
> (with DoIt) in the bottom subwindow of the '+' button inspector 
> increments the TextMorph by 1.
>
> (self target) contents: ((((self target) getNumericValue) + 1) 
> printStringBase: 10).
>
> However, a Viewer for the '+' button seems to have no target variable. 
> And a script for the button rejects "button up?" and "button down?" 
> tests with error messages.
>
> Seems I'm trying to hook up some incompatible things. How would one 
> hook up these three morphs, simply?
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20190813/44924014/attachment.html>


More information about the Beginners mailing list