• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Changing a Button Colour

Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Is it possible to change the color of a button once it has been pressed?  Say, from white to red.

TOPICS
How to

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 25, 2021 Mar 25, 2021

Use this:

event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;

Votes

Translate

Translate
Community Expert ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

As "Mouse UP" event of button use this code:

event.target.fillColor = color.red;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

That's brilliant!  Thank you.  Final question, is it possible to deselect the button so that it returns to it's initial color?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Do you mean toggle its color with each click?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Yep

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Use this:

event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Is there a place/list where I can find out what colors are available to choose from?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Like this 'color. ' you can only use these colors:
red,green,blue,cyan,magenta,yellow,white,black,transparent.
But you can use any color using either RGB codes or CMYK.
As example Il use RGB colors, for black,white and transparent you can also use like this:
transparent - ["T"]
this.getField("Text1").fillColor = ["T"];
Black - ["G",0]
White - ["G",1]
and any shades of grey between black and white ["G",0.1] ["G",0.2]...
For RGB colors you can use like this:
lets say dark green color RGB code is 0 82 33 you divide each number with 255
0 is 0, 82 is 0.32 and 33 is 0.12 so the code would be ["RGB", 0,0.32,0.12]
or you can also use it like this:
["RGB", 0/255,82/255,33/255]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Hi Nesa,

 

Thank for that.  I've almost got it.  How do I substitute the dark green to say the red or white from what you've said above?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

There is lots of sites where you can get RGB codes like this one:

https://htmlcolorcodes.com/ 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Sorry, I ment how to I write the correct code to subsitute say the dark green (or any other RGB) in the script you provided below?

 

event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Replace color.red with ["RGB", 0/255,82/255,33/255]

EDIT: full code would be:

event.target.fillColor = (color.equal(["RGB", 255/255,255/255,255/255], event.target.fillColor)) ? ["RGB", 255/255,0/255,0/255] : ["RGB", 255/255,255/255,255/255];

Or

event.target.fillColor = (color.equal(["RGB", 1,1,1], event.target.fillColor)) ? ["RGB", 1,0,0] : ["RGB", 1,1,1];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

Most helpful, and very much appreciated.  Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 17, 2023 Oct 17, 2023

Copy link to clipboard

Copied

LATEST

Can we use the button to change the color of a shape with the above code? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines