0

I'd like to change the text & colour of text of my label depending on radiobutton choice. So far I have this code;

label   $f0a.lbOPTION   -text "Watts / FTP%"    -font {Arial 10 bold}   -bg white -fg #d000d0
radiobutton $f0a.rb00 -text "Watt" -var POWsel -value 1 -font {Arial 8 bold} -bg white -fg red 
radiobutton $f0a.rb01 -text "FTP%" -var POWsel -value 0 -font {Arial 8 bold} -bg white -fg blue 
set POWsel 1

I tried adding a command to the radiobuttons, but have obviously got it wrong. I assume I need to add a -command to the 2 radiobuttons and proc that then changes the label text & colour. (I assume I'll need to change the label from -text to -textvar)?

Any help much appreciated.

added this to the radio buttons:

 -command [list togglePwr ::POWsel $f0a.$f0a.lbOPTION]
##-----------------------------------------------------------------------------
proc togglePwr {label } {
    if {[set $radiobutton]} {   
        $label configure -text "Watts" -bg white -fg red
    } else {    
        $label configure -text "FTP%" -bg white -fg blue    
    }
}
##-----------------------------------------------------------------------------
KevP
  • 1
  • 2

1 Answers1

0

I've used this proc to do what I wanted, maybe not very elegant but it works.

I also call the proc in my reset proc to put all back to default, ('POWsel' is reset to 1 in the previous line).

If someone has a far more elegant solution, please advise! :-)

##-----------------------------------------------------------------------------
proc togglePwr {} {
global POWsel f0a f1a f2a f3a f4a f5a
    if {$POWsel == 1} {
        # Power selection
        $f0a.lbOPTION           configure   -text "Enter Pwr in Watts"  -font {Arial 10 bold}   -bg white -fg red
        # Warmup
        $f1a.enSTRTPOW          configure   -font {Arial 8 }                                -bg white -fg red
        $f1a.enENDPOW           configure   -font {Arial 8 }                                -bg white -fg red
        # Cooldown  
        $f5a.enSTRTPOW          configure   -font {Arial 8 }                                -bg white -fg red
        $f5a.enENDPOW           configure   -font {Arial 8 }                                -bg white -fg red
        # Single block
        $f2a.enPOWER            configure   -font {Arial 8 }                                -bg white -fg red
        # Intervals/Recovery
        $f3a.enPOWER_HIPWR      configure   -font {Arial 8 }                                -bg white -fg red
        $f3a.enPOWER_HIPWR_END  configure   -font {Arial 8 }                                -bg white -fg red
        $f3a.enPOWER_LOPWR      configure   -font {Arial 8 }                                -bg white -fg red
        $f3a.enPOWER_LOPWR_END  configure   -font {Arial 8 }                                -bg white -fg red
        #MultiBlk
        for {set xxx 0} {$xxx < 14} {incr xxx} {
            $f4a.enPWR_$xxx     configure   -font {Arial 8 }                                -bg white -fg red
        }
    } else {        
        # Power selection
        $f0a.lbOPTION           configure   -text "Enter Pwr in %FTP"   -font {Arial 10 bold}   -bg white -fg blue  
        # Warmup
        $f1a.enSTRTPOW          configure   -font {Arial 8 }                                -bg white -fg blue
        $f1a.enENDPOW           configure   -font {Arial 8 }                                -bg white -fg blue
        # Cooldown
        $f5a.enSTRTPOW          configure   -font {Arial 8 }                                -bg white -fg blue
        $f5a.enENDPOW           configure   -font {Arial 8 }                                -bg white -fg blue
        # Single block  
        $f2a.enPOWER            configure   -font {Arial 8 }                                -bg white -fg blue
        # Intervals/Recovery
        $f3a.enPOWER_HIPWR      configure   -font {Arial 8 }                                -bg white -fg blue
        $f3a.enPOWER_HIPWR_END  configure   -font {Arial 8 }                                -bg white -fg blue
        $f3a.enPOWER_LOPWR      configure   -font {Arial 8 }                                -bg white -fg blue
        $f3a.enPOWER_LOPWR_END  configure   -font {Arial 8 }                                -bg white -fg blue
        #MultiBlk
        for {set xxx 0} {$xxx < 14} {incr xxx} {
            $f4a.enPWR_$xxx     configure   -font {Arial 8 }                                -bg white -fg blue
        }
    }   
}
KevP
  • 1
  • 2
  • I often use `option` to set widget defaults. Then we just change what we want. For example: `option add *Label*foreground red` Put it near the top of the script. – aMike Mar 19 '23 at 15:36