Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting colours to buttons that change when the button is clicked

Status
Not open for further replies.

TMPS

Technical User
May 14, 2012
2
0
0
AU
Hi Guys,

i'm sorry if this is a really obvious question but this is my first tcl/tk program.
I have been asked to create a program that displays 9 buttons that are red and when clicked become blue and vise versa. I have the 9 buttons but am unsure as how to set the colours of the buttons, any help will be greatly appreciated.

Regards,
TMPS
 
Hi

Code:
[b]for[/b] [teal]{[/teal][b]set[/b] i [purple]0[/purple][teal]}[/teal] [teal]{[/teal][navy]$i[/navy][teal]<[/teal][purple]9[/purple][teal]}[/teal] [teal]{[/teal][b]incr[/b] i[teal]}[/teal] [teal]{[/teal]
  pack [teal][[/teal]button [teal].[/teal]b[navy]$i[/navy] [teal]-[/teal]bg red [teal]-[/teal]command [green][i]"ch .b$i"[/i][/green][teal]][/teal]
[teal]}[/teal]

[b]proc[/b] ch [teal]{[/teal]b[teal]}[/teal][teal]\[/teal]
[teal]{[/teal]
  [navy]$b[/navy] configure [teal]-[/teal]bg [teal][[/teal][b]expr[/b] [teal][[/teal][b]string[/b] equal [teal][[/teal][navy]$b[/navy] cget [teal]-[/teal]bg[teal]][/teal] [green][i]"red"[/i][/green][teal]]?[/teal][green][i]"blue"[/i][/green][teal]:[/teal][green][i]"red"[/i][/green][teal]][/teal]
[teal]}[/teal]

Feherke.
 
Hi Feherke,

Thanks for your prompt reply, that's exactly what I was after.

Regards, Tom.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top