Dropdown Widgets
-
Prerequisite
Description
Dropdown widgets allow the user to select an item from a list of choices. It is easier to use compared to asking the user to input the choices in a textbox, and it also occupies less screen space compared to adding a button for each choice.
Adding the Dropdown Widget
You can use this block to add a new dropdown widget:
Parameters
- Center Position: The x and y positions of the center point of the dropdown.
- Size: The width and height of the dropdown.
- List: To specify the list of choices, you first need to create a new list, and put all the choices in that list. After that, you can specify that list in this block. For example, you can create a list named “gender”, and add 2 items to it: “Boy” and “Girl”. Then in this block, select “gender” after “using list”.
- Widget Name: The name of this dropdown, so that you can refer to it in other blocks.
When the user selects an item in the dropdown
When the user makes a selection, our program needs to respond to that. You can attach your code to this hat block:
Note that you first need to add the dropdown widget to the stage. After that, you can choose that dropdown’s name from the “Please select” menu in this block.
Selected Item in the Dropdown
To find out which item is currently selected in the dropdown, you can use this reporter block:
Note that you first need to add the dropdown widget to the stage. After that, you can choose that dropdown’s name from the “Please select” menu in this block.
Demo
In this demo, we add a dropdown named “menu1” with 2 choices. Whenever the user changes the selected value, we show that value in an alert window.