The Textbox Widget
-
Prerequisite
Description
You can use a textbox to allow the user to input some text, such as some comments, a chat message or a number.
Adding a Textbox
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1857ce67-9a2c-48a8-91f0-0c1b22b8124a.png" width="1000" style="">
Parameters
- Center Position: The x and y positions of the center point of the textbox.
- Size: The width and height of the textbox. Note that the textbox is limited to the stage window, which has a width of 480 and a height of 360.
- Padding: how much space on the left and right margin of the text.
- Line Mode: Whether there is only one line of text, or there can be multiple lines. If there is only a single line, then it will be positioned in the middle of the textbox, and the enter keys will be ignored when the user types in the textbox.
- Scroll Mode: When there are too many lines of text, whether there will be a scrollbar to scroll the textbox vertically.
- Input Mode: Whether the user can type in the textbox, or it is read-only.
- Textbox Name: A unique name to refer to this textbox later.
Reading from a Textbox
You can read the content of a textbox using this block:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/da2780a7-571a-41d5-808e-59a3af102529.png" width="450" style="">
Parameters
- Widget Name: You need to select the widget to read the value from. For a textbox, its value is the text in it.
When Value Change Event
You can listen to the event that the value of a widget has changed. For textboxes, whenever the text in it changes, this event will be triggered.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0cdf520d-e89a-450f-b43e-35a59b647792.png" width="350" style="">
Parameters
- Widget Name: You need to select the textbox to watch for the change events.
Demo
In this project, we add a textbox and a label. As we type in the textbox, its value changes, and when that event is triggered, we set the text of the label to be the content of the textbox.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6e1913f2-8ee7-48d9-a2b4-c94e06b08123.png" width="1000" style="">
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c7714057-cf1a-412d-85a9-f1e9ac195757.gif" width="500" style="border-radius: 5px; border: 1px solid #29622d;">
Try it yourself:
https://play.creaticode.com/projects/b71c2eef25e72eadcf22ab94
-
I CreatiCode pinned this topic on
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