I have the following code snippet for an application I've built for my own use. Everything currently works, but it would be 'nicer' if the entry widgets were only accessible/writable once the checkbutton was ticked.
Do I need an 'event' or can I enable/disable the entry widgets with some sort of command after the checkbutton?
I currently use the var LO_TM_ramp elsewhere in the program, does this need to change function?
TIA, KevP.
checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -var LO_TM_ramp -font {Arial 8 bold} -background white -foreground red
entry $f3a.enMINS_LOPWRb -textvar int_mins_LOb -width 2 -validate all -vcmd {ValidInt %P}
entry $f3a.enSECS_LOPWRb -textvar int_secs_LOb -width 2 -validate all -vcmd {ValidInt %P}
I have the following code snippet for an application I've built for
my own use. Everything currently works, but it would be 'nicer' if
the entry widgets were only accessible/writable once the checkbutton
was ticked.
Do I need an 'event' or can I enable/disable the entry widgets with
some sort of command after the checkbutton?
I currently use the var LO_TM_ramp elsewhere in the program, does
this need to change function?
TIA, KevP.
checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -var LO_TM_ramp -font {Arial 8 bold} -background white -foreground red
entry $f3a.enMINS_LOPWRb -textvar int_mins_LOb -width 2 -validate all -vcmd {ValidInt %P}
entry $f3a.enSECS_LOPWRb -textvar int_secs_LOb -width 2 -validate all -vcmd {ValidInt %P}
snosniv <nivpa...@gmail.com> wrote:
I have the following code snippet for an application I've built for
my own use. Everything currently works, but it would be 'nicer' if
the entry widgets were only accessible/writable once the checkbutton
was ticked.
Do I need an 'event' or can I enable/disable the entry widgets with
some sort of command after the checkbutton?
I currently use the var LO_TM_ramp elsewhere in the program, does
this need to change function?
TIA, KevP.
checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -var LO_TM_ramp -font {Arial 8 bold} -background white -foreground red
entry $f3a.enMINS_LOPWRb -textvar int_mins_LOb -width 2 -validate all -vcmd {ValidInt %P}Doing this kind of 'cross widget' interaction is one of the uses for
entry $f3a.enSECS_LOPWRb -textvar int_secs_LOb -width 2 -validate all -vcmd {ValidInt %P}
the '-command' option to the widgets. Example:
proc toggle {checkbutton entrywidget} {
if {[set $checkbutton]} {
$entrywidget configure -state normal
} else {
$entrywidget configure -state disabled
}
}
checkbutton .cb1 -variable ::cb1 -onvalue 1 -offvalue 0 \
-command [list toggle ::cb1 .ew1]
checkbutton .cb2 -variable ::cb2 -onvalue 1 -offvalue 0 \
-command [list toggle ::cb2 .ew2]
entry .ew1 -state disabled
entry .ew2 -state disabled
grid .cb1 .ew1
grid .cb2 .ew2
* snosniv <nivpa...@gmail.com>
| I used to have a variable on the checkbutton which was later tested to
| see if the entry widgets had valid data, if not a message was flagged,
| but I can't have 2 variables on the checkbutton , so how do I overcome
| this?
--<snip-snip>--
| This is my code so far (snippet), it does enable/disable the entry
| widgets nicely, but I no longer have my previous -var "LO_TM_ramp"
Why did you remove the
-var "LO_TM_ramp"
and added the
-variable ::$f3a.cbRCR_TM_RMP
for the checkbutton?
IMHO you just could have kept the LO_TM_ramp and test that in
the 'toggle' proc.
| Also, do I need the -onvalue 1 -offvalue 0, I thought ticked was 1 &
| unticked was 0 by default for the variable.
You don't need them. Sometimes it is preferred to also note the
default values in the code, so there is no doubt what is actually used.
For the default values you would need to look them up in the manual.
HTH
R'
OK, thanks for the help, but run into a different issue now.
I used to have a variable on the checkbutton which was later tested
to see if the entry widgets had valid data, if not a message was
flagged,
but I can't have 2 variables on the checkbutton , so how do I
overcome this?
Also, do I need the -onvalue 1 -offvalue 0, I thought ticked was 1 & unticked was 0 by default for the variable.
This is my code so far (snippet), it does enable/disable the entry
widgets nicely, but I no longer have my previous -var "LO_TM_ramp"
that is used later in the code.
So what do I use instead, or can I use my original var somehow?
Note that I enable/disable TWO entry widgets with ONE checkbutton
(i.e. Mins & Secs for an Interval recovery phase [indoor cycling]!).
On Thursday, 2 March 2023 at 14:43:15 UTC, Rich wrote:
snosniv <nivpa...@gmail.com> wrote:
I have the following code snippet for an application I've built for
my own use. Everything currently works, but it would be 'nicer' if
the entry widgets were only accessible/writable once the checkbutton
was ticked.
Do I need an 'event' or can I enable/disable the entry widgets with
some sort of command after the checkbutton?
I currently use the var LO_TM_ramp elsewhere in the program, does
this need to change function?
TIA, KevP.
checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -var LO_TM_ramp -font {Arial 8 bold} -background white -foreground red
entry $f3a.enMINS_LOPWRb -textvar int_mins_LOb -width 2 -validate all -vcmd {ValidInt %P}Doing this kind of 'cross widget' interaction is one of the uses for
entry $f3a.enSECS_LOPWRb -textvar int_secs_LOb -width 2 -validate all -vcmd {ValidInt %P}
the '-command' option to the widgets. Example:
proc toggle {checkbutton entrywidget} {
if {[set $checkbutton]} {
$entrywidget configure -state normal
} else {
$entrywidget configure -state disabled
}
}
checkbutton .cb1 -variable ::cb1 -onvalue 1 -offvalue 0 \
-command [list toggle ::cb1 .ew1]
checkbutton .cb2 -variable ::cb2 -onvalue 1 -offvalue 0 \
-command [list toggle ::cb2 .ew2]
entry .ew1 -state disabled
entry .ew2 -state disabled
grid .cb1 .ew1OK, thanks for the help, but run into a different issue now.
grid .cb2 .ew2
I used to have a variable on the checkbutton which was later tested to see if the entry widgets had valid data, if not a message was flagged,
but I can't have 2 variables on the checkbutton , so how do I overcome this? Also, do I need the -onvalue 1 -offvalue 0, I thought ticked was 1 & unticked was 0 by default for the variable.
This is my code so far (snippet), it does enable/disable the entry widgets nicely, but I no longer have my previous -var "LO_TM_ramp" that is used later in the code.
So what do I use instead, or can I use my original var somehow?
Note that I enable/disable TWO entry widgets with ONE checkbutton (i.e. Mins & Secs for an Interval recovery phase [indoor cycling]!).
Any help very much appreciated.
##-----------------------------------------------------------------------------
## LO power label & entry positions for VARIABLE TIME INTERVALS ##-----------------------------------------------------------------------------
label $f3a.lbLO_TIMb -text "Rcvr_Time (end)" -font {Arial 8 bold} -background white -foreground red
grid $f3a.lbLO_TIMb -row 6 -column 0
entry $f3a.enMINS_LOPWRb -textvar int_mins_LOb -width 2 -validate all -vcmd {ValidInt %P} -state disabled
entry $f3a.enSECS_LOPWRb -textvar int_secs_LOb -width 2 -validate all -vcmd {ValidInt %P} -state disabled
##### checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -var LO_TM_ramp -font {Arial 8 bold} -background white -foreground red
checkbutton $f3a.cbRCR_TM_RMP -text "On/Off" -font {Arial 8 bold} \ -background white -foreground red \
-variable ::$f3a.cbRCR_TM_RMP -onvalue 1 -offvalue 0 \
-command [list toggle ::$f3a.cbRCR_TM_RMP $f3a.enMINS_LOPWRb $f3a.enSECS_LOPWRb]
#### This now works to enable/disable the mins/secs entry widgets, but I've lost the -var LO_TM_ramp I use later in the program. :-(
grid $f3a.enMINS_LOPWRb -row 6 -column 1
grid $f3a.enSECS_LOPWRb -row 6 -column 3
grid $f3a.cbRCR_TM_RMP -row 6 -column 6
##-----------------------------------------------------------------------------
## proc to enable/disable the entry widgets on checkbox set/unset. ##-----------------------------------------------------------------------------
proc toggle {checkbutton entrywidget1 entrywidget2} {
if {[set $checkbutton]} {
$entrywidget1 configure -state normal
$entrywidget2 configure -state normal
} else {
$entrywidget1 configure -state disabled
$entrywidget2 configure -state disabled
}
} ##-----------------------------------------------------------------------------
TIA, KevP.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 297 |
Nodes: | 16 (0 / 16) |
Uptime: | 01:14:13 |
Calls: | 6,669 |
Calls today: | 1 |
Files: | 12,217 |
Messages: | 5,338,505 |