textLabel

Category:UI Controls

Creates a text label on the screen displaying the text provided and referenced by the given id at default location (0,0).

Your apps will sometimes need titles on a screen, or words next to other UI elements like radio buttons, check boxes, text inputs, and dropdown lists. If you want the text label to also trigger the events with a different UI element, you can reference that id using the optional third parameter forId.

Examples

Example: Label for a Text Input Box

Create a label and associate it with a text input box.

// Create a label and associate it with a text input box.
textLabel("YourNameLabel","Enter your name:", "YourName");
textInput("YourName","");

// Create a label for a screen title.
textLabel("screenTitle","My App");

Example Opinion Survey

Demonstrate a label for each of the user input screen elements. No event handlers have been defined yet.

// Demonstrate a label for each of the user input screen elements. No event handlers have been defined yet.
textLabel("textInputLabel","Name:", "textInputName");
textInput("textInputName","");
write("<br>");
textLabel("dropdownLabel","Year In School","dropdownYear");
dropdown("dropdownYear","Freshman","Sophomore","Junior","Senior");
write("<br>");
textLabel("radioTitleLabel", "Gender");
radioButton("radioFemale","false","genderGroup");
textLabel("radioFemaleLabel","Female","radioFemale");
radioButton("radioMale","false","genderGroup");
textLabel("radioMaleLabel","Male","radioMale");
write("<br>");
textLabel("checkBoxLabel","Excited about programming?", "checkBoxProgramming");
checkbox("checkBoxProgramming",false);

Syntax

textLabel(id, text, forId)

Parameters

NameTypeRequired?Description
id string The unique identifier for the text label. The id is used for referencing the text label 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 text label.
forId string The id of the other UI element to associate the label with.

Returns

No return value. Modifies screen only.

Tips

Found a bug in the documentation? Let us know at documentation@code.org