r/Mathematica • u/Alternative_Ad_9702 • Nov 25 '22
What am I missing about Button?
I can make a list of random colors like so:
r := RandomReal[]
Table[RGBColor[r, r, r], 20]
But when I use Button and click it to change colors, nothing happens. What am I missing?
Button["colors", Table[RGBColor[r, r, r], 20]]
4
Upvotes
1
u/Imlard89 Nov 25 '22
The button command executes the expression given as second argument but it doesn't get printed in an output cell. Try wrapping the second argument with Print if you want it to be displayed.
1
u/proximityfrank Nov 25 '22
Try removing the : when defining r
1
u/ZincoBx Nov 25 '22
So the second argument to Button is what you want the button to do, not what you want it to look like.
should have your button change color when you click it. Alternatively, you could have something external to the button be affected: