按钮控件
-
先修科目
介绍
你可以在舞台上添加按钮,并指定当用户点击按钮时会发生什么。
添加按钮
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9e5f39b2-73f7-4524-8f84-5b2a2ad0a866.png" width="700" style="">
参数
- 按钮上的文字:按钮上显示的文字。
- 中心位置:按钮中心点的x坐标、y坐标。
- 尺寸:按钮的宽度和高度。注意,按钮的尺寸不能超过舞台,舞台宽度480、高度360。
- 提示信息:当鼠标在按钮上悬停时所展示的文本。常用于在用户点击按钮之前展示按钮的功能信息。
- 按钮名称:名称必须唯一,之后用名称引用该按钮。
编排按钮点击事件
每当点击按钮,这个积木就运行它下面的代码。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b554c78c-74c5-44ef-ab30-af926555a6ee.png" width="250" style="">
参数
- 控件名称:需要选择鼠标点击事件所关联的按钮名称。必须先把按钮添加到舞台中,其名称才会出现于下拉列表中。
范例
下方录屏展示了如何添加按钮,以及每当用户点击按钮,上面的文字就会改变。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f27e0a42-c2e7-4e39-940a-dd93be84cd49.gif" width="500" style="border-radius: 5px; border: 1px solid #29622d;">
为了使文字在“开始”和“停止”之间切换,用一个变量“命令”来跟踪当前命令。每当点击按钮,我们就根据“命令”的当前值更改“命令”。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fb7bcc8f-2608-47f5-986e-ca96ca33380a.png" width="700" style="">
亲自尝试
https://play.creaticode.com/projects/9569e7bf0eb49d0afa9aa99a
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