Getting a scale value put onto a label... 
Author Message
 Getting a scale value put onto a label...

Hi,

This should be very quick to answer.

I want to have a scale with the scale value printed on the left of the scale
on a label, I want it to change as the scale moves.

Here is the relevant code:
set pl1low 1
label .pal1low -textvariable pl1low \
        -font -*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*
scale .s1palw -from 0 -to 100 -length 75m -orient horizontal \
        -label "Threshold range width" \
        -command "set $pl1low [.s1palw get]"

Can someone help me?
This gets an error:
invalid command name ".s1palw"
    while executing
".s1palw get"
    invoked from within
"scale .s1palw -from 0 -to 100 -length 75m -orient horizontal \
        -label "Threshold range width" \
        -command "set $pl1low [.s1palw get]..."
    (file "gui" line 100)
    invoked from within

I'm not sure what is wrong. Rather than correct my code, what is the
popular way to do this? (display a scale value in a label).

thanks,
And thankyou to all those who posted and mailed help to my other question.
wayne.



Fri, 10 Jan 1997 14:40:14 GMT  
 Getting a scale value put onto a label...

|> Hi,
|>
|> This should be very quick to answer.
|>
|> I want to have a scale with the scale value printed on the left of the scale
|> on a label, I want it to change as the scale moves.
|>
|> Here is the relevant code:
|> set pl1low 1
|> label .pal1low -textvariable pl1low \
|>         -font -*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*
|> scale .s1palw -from 0 -to 100 -length 75m -orient horizontal \
|>         -label "Threshold range width" \
|>         -command "set $pl1low [.s1palw get]"
|>
|> Can someone help me?
|> This gets an error:
|> invalid command name ".s1palw"
|>     while executing
|> ".s1palw get"
|>     invoked from within
|> "scale .s1palw -from 0 -to 100 -length 75m -orient horizontal \
|>         -label "Threshold range width" \
|>         -command "set $pl1low [.s1palw get]..."
|>     (file "gui" line 100)
|>     invoked from within
|>
|> I'm not sure what is wrong.

Quoting problem. While the scale command is being parsed, ".s1palw" is not a
command yet, so Tcl can't execute the [.s1palw get] to substitute the return
value inside the string.

However you don't really want to do that, not even conceptually: otherwise the
command would always put the same value into the variable, namely the value at
parse time instead of the value at execution time.  So your intention is better
expressed by wrapping the -command option in {}s instead of "".

But there are a couple more things to note: (1) you don't need the [.s1palw get]
at all, because the current value of the scale is appended "for free" to the
-command before evaluation. (2) you should say "set pl1low ..." instead of "set
$pl1low ..." (I'm sure this is just a typo).

In summary, replace your last line with

   -command "set pl1low"

(note that {}s and ""s are the same now, because no substitutions are invoked.)

|> Rather than correct my code, what is the
|> popular way to do this? (display a scale value in a label).

I'd say that the popular way is to stick with the value that is displayed for
free under the cursor... But if you have for some reason the need to have it in
a label, then your approach looks just fine to me.

BTW, you'll be interested to know that Tk 4.0 will have a -variable option for
scales that will work just like it does in checkbuttons and radiobuttons, so
these little acrobatics won't be necessary anymore.
--

    Frank   (Filologo Disneyano)



Sun, 12 Jan 1997 02:01:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting rid of scale labels in scale legends?

2. putting different image textures onto different box faces

3. Injecting a value onto the stack

4. writing output listing onto screen (or not) and onto file

5. Does tk support scrollbar for label/scale widgets ?

6. Q: Put 2 line label in a button

7. newbie: Getting widget sizes after scaling window.

8. access the properties of an xy-plot (eg: cursor x,y values, scale etc)

9. Scale an object to a defined value

10. tkWinColor.c scales color values incorrectly.

11. passing values from scales

12. Starting a scale at non-zero value

 

 
Powered by phpBB® Forum Software