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:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/62abd0ef-6da3-4c03-9b97-d46175f4be4c.png" width="700" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
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”.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/94544c40-6ad0-49c5-9e23-248c2491695e.png" width="800" style="margin-left: 40px; border-radius: 5px; border: 1px solid #29622d;">
- 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:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0f856e05-16cf-47ba-bf08-c1f44ccdc64b.png" width="400" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
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:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/47701176-b93f-4297-9466-b844c31d3035.png" width="500" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
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.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fc124063-28a0-45bc-965c-dcede37ef558.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login