Navigation

    CreatiCode Scratch

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    The Button Widget

    2D Blocks
    1
    1
    105
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by info-creaticode

       

      Prerequisite

      • The Label Widget
      • Setting Text on Widget

       

      Description

      You can add buttons to the stage, and specify what happens when the user clicks on them.

       

      Adding a Button

       

      Parameters

      • Text on Button: The text to be displayed on the button.
      • Center Position: The x and y positions of the center point of the button.
      • Size: The width and height of the button. Note that the button is limited to the stage window, which has a width of 480 and a height of 360.
      • Tooltip: The text to be displayed when the mouse is hovering over the button. This is often useful when you want to show some information about what the button does before the user clicks on it.
      • Button Name: A unique name to refer to this button later.

       

      Handle the Button Click Event

      This block allows you to run some code whenever the button is clicked.

       

      Parameters

      • Widget Name: You need to select the name of the button for which you are waiting for the click event. That button has to be added to the stage already for its name to show up in this list.

       

      Demo

      This screencast shows how to add a button, and then change the text on it whenever the user clicks on it.

      To make the text toggle between “Start” and “Stop”, a variable “Command” is used to keep track of the current command. Each time the button is clicked, we change “Command” based on its current value.

       

      Try it yourself:

      https://play.creaticode.com/projects/11550cc1f7d8230ae73123af

      1 Reply Last reply Reply Quote 0
      • Pinned by  info-creaticode info-creaticode 
      • First post
        Last post