Navigation

    CreatiCode Scratch Forum

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

    The Radio Button Group Widget

    2D Blocks
    1
    1
    173
    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 admin

      Introduction

      A radio button is also called an option button. It is actually a group of buttons, and only one of the buttons in a group can be selected. If you select any button, then the previously selected button in this group will become unselected. Radio buttons are most useful when you need to give the user a few choices, but only want the user to pick one of them.

      To add a group of radio buttons, use the following block:

      343093f7-ba1a-4421-8ab2-e46c9ce38091-image.png

       
      Parameters:

      • The 6 inputs allow us to specify up to 6 different choices. If you only want to offer 3 options, then fill in the first 3 input fields.
      • The radio buttons can be arranged vertically or horizontaly.
      • You can specify the position and size of the radio button group
      • Lastly, you can give this group a name.

       
      For example, the following program adds 2 groups of radio buttons. These 2 groups are independent of each other.

      f37cea01-b7a2-40d6-81ac-858c9b6abc65-image.png

       

      rg.gif

       
       

      Set Value To a Radio Button Group

      To make sure one of the radio buttons is selected by default, you can use the “set value to widget” block. You have to use one of the options as the new value:

      f2136a5f-1cf7-41f1-b499-46620805a3db-image.png

        The above program will produce this:

      a1e74875-90e7-4a88-87ea-fb84bc93a065-image.png

       
       

      Handle Value Changes

      To make your program “reactive”, you can run some code whenever the value of the radio button group changes. To do that, you need to use the “when widget changes” block to handle the change event, and use the “value of” block to read the currently selected option of the group.

      For example, the following program sets a different color effect based on the user’s selection:

      rg2.gif

       
      Similarly, the following program changes the sprite’s direction based on the second radio button group:

      rg3.gif

      1 Reply Last reply Reply Quote 0
      • First post
        Last post