Creates a button on the screen displaying the text provided and referenced by the given id at default location (0,0).
Many apps use buttons to allow the user to initiate some app action. An event handler must be created for each type of user interaction with the button using onEvent()
and the id.
Found a bug in the documentation? Let us know at documentation@code.org
Move the turtle forward on every click of the button.
// Move the turtle forward on every click of the button. button("forward", "Move Forward"); onEvent("forward", "click", function(event) { moveForward(); });
Move the turtle forward or backward depending on the button clicked.
// Move the turtle forward or backward depending on the button clicked. button("forward", "Move Forward"); button("backward", "Move Backward"); onEvent("forward", "click", function(event) { moveForward(); }); onEvent("backward", "click", function(event) { moveBackward(); });
// Create a "Click Me" button. button("id", "Click Me!");
button(id, text)
Name | Type | Required? | Description |
---|---|---|---|
id | string | The unique identifier for the button. The id is used for referencing the button in event handlers or other UI element modification functions. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _. | |
text | string | The text displayed within the button. |
No return value. Modifies screen only.
setText()
, showElement()
, hideElement()
, deleteElement()
, setPosition()
, setSize()
. getText()
, getXPosition()
, getYPosition()
.Found a bug in the documentation? Let us know at documentation@code.org