The Checkbox Widget
-
Introduction
Checkboxes are very often used in apps to allow the user to quickly input their answers to “yes/no” type of questions or configure settings on certain options.
To add a checkbox, you can use the following block:
X and Y are the positions of the checkbox. The last input is the name of the checkbox, which can be used to refer to this checkbox later.
Checkbox + Label
To show the user the meaning of each checkbox, we can add a label next to the checkbox. For example, this program would add a checkbox for the user to specify whether something is visible or not:
Set the Value of a Checkbox
Usually, we may want to set a checkbox to be checked or unchecked by default. This can be done right after we add a checkbox. We can use the “set value to” block: a value of 0 will make the checkbox unchecked, and 1 will make it checked:
React to Value Changes
Whenever the user clicks the checkbox, we can handle that event using the “when widget changed” block, and read the updated value of the checkbox widget.
For example, this program will use the checkbox to control whether the sprite is shown or hidden: