tcl/tk slider example program

Copy the following text, and paste into new file, saving as tconvert.tcl, chmod 755 tconvert.tcl then ./tconvert.tcl

#!/bin/bash
# script to convert between F and C
# \
exec wish “$0″ ${1+”$@”}

# set window title
wm title . “Temperature Converter”

# convert C to F
proc celsiusTofahren { ctemp } {
global fahrenheit
set fahrenheit [ expr ($ctemp * 1.8) + 32 ]
}

# convert F to C
proc fahrenToCelsius { ftemp } {
global celsius
set celsius [ expr ($ftemp – 32 ) / 1.8 ]
}

# create a scale for f temps
set fahrenscale [ scale .fht -orient horizontal \
-from 0 -to 212 -length 500 \
-resolution .1 -tickinterval 20 -label “Fahrenheit” \
-variable fahrenheit -command fahrenToCelsius ]

# create a scale for c temps
set celscale [ scale .cel -orient horizontal \
-from -20 -to 100 -length 500 \
-resolution .1 -tickinterval 20 -label “Celsius” \
-variable celsius -command celsiusTofahren ]

# Grid the widgets
grid $fahrenscale
grid $celscale