Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:13:24+00:00 2026-06-03T12:13:24+00:00

Just making a really simple Tcl/Tk program to learn, but I’m having a little

  • 0

Just making a really simple Tcl/Tk program to learn, but I’m having a little trouble.

I need to make a button switch colours when clicked, so it will start red, when clicked it will turn green, and if clicked again will go back to red.

I have got it changing from red to green, but I don’t know how to make it go back the other way.
What is the best way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:13:26+00:00Added an answer on June 3, 2026 at 12:13 pm

    It’s not very hard (except on OSX, where this sort of thing is directly against platform UI guidelines) you just need to use a suitable callback:

    button .b -background red -command [list toggleTheButton .b]
    set state(.b) 1
    proc toggleTheButton w {
        global state
        if {$state($w)} {
            $w configure -background green
        } else {
            $w configure -background red
        }
        set state($w) [expr {!$state($w)}]
    }
    

    Consider using a checkbutton instead when you need toggling, as it will be much more rapidly understood by the users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe a simple question but I'm having alot of trouble making a button change
I just learn the bare bone of making a thread inside a program using
I've been trying to make a little simple game just to test my logics,
I came across this (really) simple program a while ago. It just outputs the
I'm making a really simple email validation script that basically just checks the following
I'm probably making a really simple error somewhere, but for some reason the event
I have just started making web pages and I'm having lots of trouble with
I know this is probably a really simple question but I'm having a brain
Okay, I think I'm just making a stupid mistake here, but I want to
I dunno guys, this is a really weird one, but I might just be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.