Introduction to Widgets with the Label Widget
-
Prerequisite
Description
Widgets are GUI elements (e.g. labels or buttons) for displaying information and taking user inputs. They can be used in both 2D and 3D projects.
Let’s look at labels as the first example widget. They are often used when we need to show some information to the user.
Adding the Widget Extension
Here is how to add the widget extension
Adding a Label Widget
To add a new label, you can use the “add label” block:
Parameters
- Text on Label: You can write some text on the label, or leave it blank.
- Center Position: The x and y positions of the center point of the label.
- Size: The width and height of the label. Note that the label is limited to the stage window, which has a width of 480 and a height of 360.
- Widget Name: You need to assign a unique name to any widget you add, so that you can refer to it later using that name. If you use a name that is already used by another widget, that widget will be removed first.
Removing a Widget
You can remove any widget using the “remove widget” block:
Parameters
- Widget Name: You have to select a valid name of an existing widget from the list. Note that to populate this list, you have to run the block that adds the widget first.
Demo
In this screencast, we first add 2 labels “start label” and “stop label”, then remove the “stop label”. Note that the dropdown for removal is empty before the labels are added.
Removing All Widgets
In case you need to remove all the widgets, you can use this block:
Note that when the user clicks the green flag button, all widgets will be removed, so it is not necessary to use “remove all widgets” at the very beginning of your project.
-