#!/usr/bin/wish -f ## ##+####################################################################### ## NOTE: ## If the 'wish' interpreter is in another directory, like ## /usr/local/bin, you, as root, can make a soft-link from 'wish' there ## to /usr/bin/wish --- with a command like ## ln -s /usr/bin/local/wish /usr/bin/wish ## The form of this command: ## ln -s ##+####################################################################### ## Tk SCRIPT NAME: tkTemperature-Convert-Select_F-C-K.tk ## ##+####################################################################### ## PURPOSE: This TkGUI script provides a GUI for showing temperatures ## between absolute zero and several thousand degrees --- ## in three different units: ## - Fahrenheit ## - Centigrade ## - Kelvin. ## ## These 3 different units are shown (and selected for conversion) ## via 3 'sliders' of 3 Tk 'scale' widgets. ## ## These 3 different (corresponding) numbers are also shown ## in 3 'text' widgets, a few characters wide --- from which ## a user can copy-and-paste the numbers from this GUI window ## to some other window. ## ## For any (completed) 'slider' change, this GUI script updates ## the location of the other 2 'sliders'. ## ## The 3 text widgets, showing the temperature in the 3 different ## units, are also updated whenever any one of the 3 scale widget ## 'sliders' are changed. ## ## By clicking on a 'UseIt' button on the GUI, this script ## returns a string containing the current temperature (in the ## 3 different units) to a calling script/application. ## ## This script will accept a temperature (in Centigrade) as an ## argument, which is used to initialize the ## - setting of the 3 'sliders', and ## - the numbers shown in the 3 small text widgets. ## ## SOME USES: ## ## 1) Useful for helping math-science students get a visual ## 'feel' for the relation between Fahrenheit, Centigrade, ## and Kelvin. ## ## 2) Also could be useful for programmers (example: Tcl-Tk programmers) ## for determining temperatures (example: Centigrade from Fahrenheit) ## to be used in various Tcl-Tk apps. ## ## 3) IN A SHELL SCRIPT OR ANOTHER TK SCRIPT, this Tk script can ## ACT AS AN TEMPERATURE SELECTOR by passing the current temperature ## (in the 3 different units) to stdout, when the OK/UseIt button ## is clicked. ## Example output string: 32.0 0.0 273.0 ## (Fahrenheit,Centigrade,Kelvin) ##+######################################################################## ## 'CANONICAL' STRUCTURE OF THIS CODE: ## ## 0) Set general window parms (win-name, win-position, win-color-scheme, ## fonts, widget-geom-parms, win-size-control, text-array-for-labels-etc). ## 1a) Define ALL frames (and sub-frames). ## 1b) Pack ALL the frames and sub-frames. ## 2) Define & pack all widgets in the frames, frame by frame. ## ## 3) Define key and mouse/touchpad/touch-sensitive-screen 'event' ## BINDINGS, if needed. ## 4) Define PROCS, if needed. ## 5) Additional GUI INITIALIZATION (typically with one or two ## procs in section 4), if needed. ## ##+################################# ## The code structure in more detail, for this particular script: ## ## 1a) Define ALL frames: ## ## Top-level : ## ## 'fRbuttons' - to contain several buttons --- UseIt,Cancel,Help ## ## 'fRtexttemps' - to contain 3 pairs of label-and-text widgets to ## display the current temperature, in the 3 different ## units, in the 3 text widgets. ## ## 'fRinfo' - to contain a label widget, with changeable ## temperature and material-melting/boiling info ## ## 'fRsliders' - to contain 3 sliders - 'scale' widgets, along with ## 3 'label' widgets. ## ## Sub-frames: 'fRsliders.fRfahr' , 'fRsliders.fRcent' , 'fRsliders.fRkelv' ## ## 'fRbuttons' is to be on the top of the GUI, ## 'fRtexttemps' is to be just below that frame, and ## 'fRinfo' is to be just below that frame, and ## 'fRsliders' is to be on the bottom of the GUI. ## ## The 'fRfahr', 'fRcent', 'fRkelv' sub-frames of the 'fRsliders' frame ## are to be packed left to right. ## ## The 3 scale widgets are to be oriented vertically in the ## 3 sub-frames. ## ## 1b) Pack ALL frames. ## ## 2) Define & pack all widgets in the frames -- basically going through ## frames & their interiors in top-to-bottom and/or left-to-right order: ## ## 3) Define BINDINGS: button-1 release bindings on the 3 scale widgets ## cause a call to the 'temperature_update' proc. ## For details, see the BINDINGS code section below. ## ## 4) Define PROCS: ## 'temperature_update' - called by button1-release bindings on 3 scale widgets. ## (One could someday try calling this proc in the ## '-command' options on the 3 scales.) ## 'set_temperatureColor' - called by the 'temperature_update' proc ## 'get_centitext' - called by the 'temperature_update' proc ## 'put_vars' - called by the 'UseIt' button ## 'popup_msg_var_scroll' - called by the 'Help' button ## ## 5) Additional GUI INITIALIZATION: set the HELPtext var for the Help button ## and set a list-and-array for holding ## melting-boiling/freezing-condensing info. ## ##+####################################################################### ## DEVELOPED WITH: ## Tcl-Tk 8.5 on Ubuntu 9.10 (2009-october release, 'Karmic Koala'). ## ## $ wish ## % puts "$tcl_version $tk_version" ## showed 8.5 8.5 on Ubuntu 9.10 ## after Tcl-Tk 8.4 was replaced by 8.5 --- to get anti-aliased fonts. ##+######################################################################## ## MAINTENANCE HISTORY: ## Created by: Blaise Montandon 2013aug22 Started on Ubuntu 9.10, based ## on the color-selector script ## of the FE (Freedom Environment) ## subsystems. Ref: www.freedomenv.com ## Changed by: Blaise Montandon 2013aug23 Added frame 'fRinfo'. Changed the ## formula for the palette color change. ## Changed by: Blaise Montandon 2013aug24 Added vars LISTcentipairs,aRcentitext. ## Changed by: Blaise Montandon 2014jan16 Added a separate 'fRtextemps' frame. ## Implemented the 'get_centitext' proc. ## Added a color-setting method to the ## 'set_temperatureColor' proc. ##+############################################################################ ##+################################# ## SET THE TOP WINDOW NAME. ##+################################# wm title . \ "tkTemperature-Convert-Select - Fahrenheit, Centigrade, Kelvin" wm iconname . "Temperature" # catch { wm title . "$env(FE_WIN_TITLE)" } # catch { wm iconname . "$env(FE_ICON_TITLE)" } ##+################################### ## SET THE TOP WINDOW POSITION. ##+################################### wm geometry . +15+30 # catch {eval wm geometry . "$env(FE_TEMPERATURESEL_GEOM)" } ##+####################################################################### ## SET COLOR SCHEME (palette) FOR THE WINDOW. ##+####################################################################### if {1} { ## Gray palette set Rpal255 210 set Gpal255 210 set Bpal255 210 } if {0} { ## Bluish palette set Rpal255 100 set Gpal255 0 set Bpal255 255 } if {0} { ## Redish palette set Rpal255 255 set Gpal255 0 set Bpal255 100 } ## NOTE: Although we set the window palette here, we could reset ## the color 'dynamically', according to current Kelvin value, ## in the proc 'temperature_update'. set hexCOLORpal [format "#%02X%02X%02X" $Rpal255 $Gpal255 $Bpal255] tk_setPalette $hexCOLORpal ## Set color background for some widgets. # set radbuttBKGD "#c0c0c0" # set chkbuttBKGD "#c0c0c0" # set listboxBKGD "#f0f0f0" # set entryBKGD "#f0f0f0" set textBKGD "#f0f0f0" ##+####################################################################### ## SET FONT ATTRIBUTE VARS to use in the 'font create' statements below. ##+####################################################################### set FONTsize 14 set FONT_SMALLsize 12 ## For variable width: set FONT_varwidth \ " -family {comic sans ms} -size -$FONTsize -weight bold -slant roman " set FONT_SMALL_varwidth \ " -family {comic sans ms} -size -$FONT_SMALLsize -weight normal -slant roman " ## For fixed width: set FONT_fixedwidth \ " -family {dejavu sans mono} -size -$FONTsize -weight bold -slant roman " set FONT_SMALL_fixedwidth \ " -family {dejavu sans mono} -size -$FONT_SMALLsize -weight normal -slant roman " ##+##################################################################### ## DEFINE (temporary) 'font create' NAMES to be used ## in '-font' widget specs below. ##+##################################################################### eval font create fontTEMP_button $FONT_varwidth eval font create fontTEMP_label $FONT_varwidth eval font create fontTEMP_scale $FONT_varwidth # eval font create fontTEMP_entry $FONT_fixedwidth # eval font create fontTEMP_listbox $FONT_fixedwidth # eval font create fontTEMP_msg $FONT_fixedwidth eval font create fontTEMP_text $FONT_fixedwidth # eval font create fontTEMP_SMALL_button $FONT_SMALL_varwidth # eval font create fontTEMP_SMALL_label $FONT_SMALL_varwidth # eval font create fontTEMP_SMALL_scale $FONT_SMALL_varwidth # eval font create fontTEMP_SMALL_entry $FONT_SMALL_fixedwidth # eval font create fontTEMP_SMALL_listbox $FONT_SMALL_fixedwidth # eval font create fontTEMP_SMALL_msg $FONT_SMALL_fixedwidth # eval font create fontTEMP_SMALL_text $FONT_SMALL_fixedwidth ##+####################################################################### ## SET GEOM VARS FOR THE VARIOUS WIDGET DEFINITIONS. ## (e.g. padx,pady for buttons) ##+####################################################################### ## For BUTTON widgets: set PADYpx_button 0 set PADXpx_button 0 set BDwidthPx_button 2 ## For LABEL widgets: set PADXpx_label 0 set PADYpx_label 0 set BDwidthPx_label 2 ## SCALE geom parameters: set BDwidthPx_scale 2 ## For TEXT widgets: set BDwidthPx_text 2 if {0} { ## CANVAS geom parms: set initCanWidthPx 200 set initCanHeightPx 200 set minCanHeightPx 24 # set BDwidthPx_canvas 2 set BDwidthPx_canvas 0 } ## For ENTRY widgets: # set BDwidthPx_entry 2 ## For LISTBOX widgets: # set BDwidthPx_listbox 2 ##+################################################################### ## Set a MINSIZE of the window (roughly). ## ## For WIDTH, allow for a minwidth of the '.fRbuttons' frame: ## about 3 buttons (UseIt,Cancel,Help). OR allow for a ## minwidth of the '.fRtexttemps' frame: 3 pairs ## of label-and-text widgets. ## ## For HEIGHT, allow about ## 1 char high for the '.fRbuttons' frame ## 1 char high for the '.fRtexttemps' frame ## 1 char high for the '.fRinfo' frame ## 300 pixels high for the '.fRsliders' frame. ##+####################################################################### ## NOTE: ## We allow the window to be resizable and we pack the 'fRsliders' frame ## with '-fill both -expand 1' so that the sliders frame can be enlarged by ## enlarging the window. ##+####################################################################### # set minWinWidthPx [font measure fontTEMP_button \ # " UseIt Cancel Help" set minWinWidthPx [font measure fontTEMP_button \ "Fahrenheit: 32.0 Centigrade: 0.0 Kelvin: 273.0"] ## Add some pixels to account for right-left-side window decoration ## (about 8 pixels), about 6 widgets x 4 pixels/widget for borders/padding ## for 6 widgets --- label-and-text widget pairs. set minWinWidthPx [expr {32 + $minWinWidthPx}] ## MIN HEIGHT --- ## 1 char high for the '.fRbuttons' frame ## 1 char high for the '.fRtexttemps' frame ## 1 char high for the '.fRinfo' frame ## 300 pixels high for the '.fRsliders' frame set CharHeightPx [font metrics fontTEMP_varwidth -linespace] set minWinHeightPx [expr {300 + (3 * $CharHeightPx)}] ## Add about 28 pixels for top-bottom window decoration, ## about 3 frames x 4 pixels/frame for each of the 3 stacked frames ## and their widgets (their borders/padding). set minWinHeightPx [expr {40 + $minWinHeightPx}] ## FOR TESTING: # puts "minWinWidthPx = $minWinWidthPx" # puts "minWinHeightPx = $minWinHeightPx" wm minsize . $minWinWidthPx $minWinHeightPx ##+############################################# ## If you want to make the window un-resizable, ## you can use the following statement. ##+############################################# # wm resizable . 0 0 ##+######################################################################## ## Set a TEXT-ARRAY to hold text for buttons & labels on the GUI. ## NOTE: This can aid INTERNATIONALIZATION. This array can ## be set according to a nation/region parameter. ##+######################################################################## ## if { "$VARlocale" == "en"} ## For '.fRbuttons' frame: set aRtext(buttonUSEIT) "UseIt" set aRtext(buttonCANCEL) "Cancel" set aRtext(buttonHELP) "Help" ## For '.fRtexttemps' frame: set aRtext(labelTEXTfahr) "Fahrenheit:" set aRtext(labelTEXTcent) " Centigrade:" set aRtext(labelTEXTkelv) " Kelvin:" ## For '.fRsliders' sub-frames: set aRtext(labelSCALEfahr) "Fahrenheit:" set aRtext(labelSCALEcent) "Centigrade:" set aRtext(labelSCALEkelv) "Kelvin:" ## END OF if { "$VARlocale" == "en" ##+######################################################################## ## ## GET INPUT PARM VALUE -- ## i.e. set VARcent from ## ## 1) an argument passed to this script ## OR ## 2) environment var VAR_CENTIGRADE ## ##+######################################################################## ##+######################################################################## ## Example argc/argv processing: ## ## if {$argc == 0} { ## set VARtext "$env(CONFIRM_TEXT)" ## } else { ## set VARtext [lindex $argv 0] ## } ##+######################################################################## if {$argc == 1} { set VARcent [lindex $argv 0] } else { set VARcent 0 catch { set VARcent "$env(VAR_CENTIGRADE)" } } set VARfahr [expr {(9.0 * $VARcent / 5.0) + 32}] set VARkelv [expr {$VARcent + 273.15}] ##+#################################################################### ## DEFINE *ALL* THE FRAMES: ## TOP-LEVEL FRAMES: ## - 'fRbuttons' - to contain several buttons (UseIt,Cancel,Help) ## - 'fRtexttemps' - to contain 3 pairs of label-and-text widgets. ## - 'fRinfo' - to contain a label widget. ## - 'fRsliders' - to contain 3 sliderbars, with 3 labels. ## ## 'fRsliders' is packed below the 'fRbuttons' frame. ## ## SUB-FRAMES: (to contain each of the 3 scale widgets) ## - 'fRsliders.fRfahr' ## - 'fRsliders.fRcent' ## - 'fRsliders.fRkelv' ## ##+#################################################################### ## FOR TESTING: (like expansion of frames, during window expansion) # set RELIEF_frame raised # set BDwidth_frame 2 set RELIEF_frame flat set BDwidth_frame 0 frame .fRbuttons -relief $RELIEF_frame -borderwidth $BDwidth_frame # frame .fRtexttemps -relief raised -borderwidth 2 frame .fRtexttemps -relief $RELIEF_frame -borderwidth $BDwidth_frame frame .fRinfo -relief $RELIEF_frame -borderwidth $BDwidth_frame frame .fRsliders -relief $RELIEF_frame -borderwidth $BDwidth_frame frame .fRsliders.fRfahr -relief raised -borderwidth 2 frame .fRsliders.fRcent -relief raised -borderwidth 2 frame .fRsliders.fRkelv -relief raised -borderwidth 2 ##+######################################################## ## PACK *ALL* the FRAMES. ##+######################################################## pack .fRbuttons \ -side top \ -anchor nw \ -fill x \ -expand 0 pack .fRtexttemps \ -side top \ -anchor nw \ -fill x \ -expand 1 pack .fRinfo \ -side top \ -anchor nw \ -fill x \ -expand 1 pack .fRsliders \ -side top \ -anchor nw \ -fill both \ -expand 1 ## Pack the sub-frames. pack .fRsliders.fRfahr \ .fRsliders.fRcent \ .fRsliders.fRkelv \ -side left \ -anchor center \ -fill y \ -expand 1 ##+################################################################ ## The frames are now defined and packed. ##+################################################################ ## START DEFINING & PACKING WIDGETS WITHIN THEIR FRAMES. ##+################################################################ ##+################################################################ ##+######################################################## ## IN THE 'fRbuttons' frame -- DEFINE several BUTTONS --- ## 1 'UseIt' BUTTON, 1 'Cancel' BUTTON, 1 'Help' BUTTON. ## THEN PACK THE WIDGETS. ##+######################################################## button .fRbuttons.buttUSEIT \ -text "$aRtext(buttonUSEIT)" \ -font fontTEMP_button \ -padx $PADXpx_button \ -pady $PADYpx_button \ -relief raised \ -bd $BDwidthPx_button \ -command {put_vars} button .fRbuttons.buttCANCEL \ -text "$aRtext(buttonCANCEL)" \ -font fontTEMP_button \ -padx $PADXpx_button \ -pady $PADYpx_button \ -relief raised \ -bd $BDwidthPx_button \ -command {exit} button .fRbuttons.buttHELP \ -text "$aRtext(buttonHELP)" \ -font fontTEMP_button \ -padx $PADXpx_button \ -pady $PADYpx_button \ -relief raised \ -bd $BDwidthPx_button \ -command {popup_msgVarWithScroll .topHelp "$HELPtext"} ## Pack the widgets in frame 'fRbuttons'. pack .fRbuttons.buttUSEIT \ .fRbuttons.buttCANCEL \ .fRbuttons.buttHELP \ -side left \ -anchor w \ -fill none \ -expand 0 ##+######################################################## ## IN THE 'fRtexttemps' frame -- DEFINE ## 3 'TEXT' WIDGETS (rather than a 'label' or 'message' widget, ## so that it is possible to paste the text values ## to another window). Each text widget with a label widget. ## THEN PACK THE WIDGETS. ##+######################################################## ## Provide label-and-text widgets for the temperature values ## in several different units. set widthTextWidgetChars 10 set textWidgetFiller " " ## FAHRENHEIT: label .fRtexttemps.labTEXTfahr \ -text "$aRtext(labelTEXTfahr)" \ -font fontTEMP_label \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label text .fRtexttemps.txtVARfahr \ -relief raised \ -borderwidth $BDwidthPx_text \ -height 1 \ -width $widthTextWidgetChars \ -wrap none \ -font fontTEMP_text ## CENTIGRADE: label .fRtexttemps.labTEXTcent \ -text "$aRtext(labelTEXTcent)" \ -font fontTEMP_label \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label text .fRtexttemps.txtVARcent \ -relief raised \ -borderwidth $BDwidthPx_text \ -height 1 \ -width $widthTextWidgetChars \ -wrap none \ -font fontTEMP_text ## KELVIN: label .fRtexttemps.labTEXTkelv \ -text "$aRtext(labelTEXTkelv)" \ -font fontTEMP_label \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label text .fRtexttemps.txtVARkelv \ -relief raised \ -borderwidth $BDwidthPx_text \ -height 1 \ -width $widthTextWidgetChars \ -wrap none \ -font fontTEMP_text ## Pack the widgets in frame '.fRbuttons'. pack .fRtexttemps.labTEXTfahr \ .fRtexttemps.txtVARfahr \ .fRtexttemps.labTEXTcent \ .fRtexttemps.txtVARcent \ .fRtexttemps.labTEXTkelv \ .fRtexttemps.txtVARkelv \ -side left \ -anchor w \ -fill none \ -expand 0 ##+######################################################## ## IN THE 'fRinfo' frame -- DEFINE ## a LABEL widget. ##+######################################################## ## The text for this button will be inserted as the ## sliders are moved, by the 'get_centitext' proc below. label .fRinfo.labelINFO \ -text "" \ -font fontTEMP_label \ -justify center \ -anchor center \ -padx $PADXpx_label \ -pady $PADYpx_label \ -relief flat \ -bd $BDwidthPx_label pack .fRinfo.labelINFO \ -side left \ -anchor w \ -fill x \ -expand 1 ##+######################################################## ## Prepare some variables for use in defining the ## 3 scales below. ##+######################################################## set scaleLenPx 350 set scaleThickPx 10 set KELVmin 0 set KELVmax 4000.0 set CENTmin [expr {$KELVmin - 273.15}] set CENTmax [expr {$KELVmax - 273.15}] set FAHRmin [expr {(9.0 * $CENTmin / 5.0) + 32.0}] set FAHRmax [expr {(9.0 * $CENTmax / 5.0) + 32.0}] # set resolution 0.1 # set digits 5 set resolution 1 set digits 4 ##+######################################################## ## IN THE 'fRsliders.fRfahr' frame -- DEFINE ## a LABEL widget and a SCALE widget. ## The scale is oriented vertically. ## THEN PACK THEM --- the label above the scale. ##+######################################################## ## FAHRENHEIT: label .fRsliders.fRfahr.label \ -text "$aRtext(labelSCALEfahr)" \ -font fontTEMP_label \ -width 9 \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label scale .fRsliders.fRfahr.scale \ -orient vertical \ -from $FAHRmax -to $FAHRmin \ -resolution $resolution \ -digits $digits \ -length $scaleLenPx \ -variable VARfahr \ -font fontTEMP_scale \ -showvalue true \ -bd $BDwidthPx_scale \ -width $scaleThickPx ## -command {temperature_update} .fRsliders.fRfahr.scale set $VARfahr ##+################################################# ## Pack the widgets in the frame '.fRsliders.fRfahr'. ##+################################################# pack .fRsliders.fRfahr.label \ -side top \ -anchor nw \ -fill none \ -expand 0 pack .fRsliders.fRfahr.scale \ -side top \ -anchor nw \ -fill y \ -expand 1 ##+######################################################## ## IN THE 'fRsliders.fRcent' frame -- DEFINE ## a LABEL widget and a SCALE widget. ## The scale is oriented vertically. ## THEN PACK THEM --- the label above the scale. ##+######################################################## ## CENTIGRADE: label .fRsliders.fRcent.label \ -text "$aRtext(labelSCALEcent)" \ -font fontTEMP_label \ -width 9 \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label scale .fRsliders.fRcent.scale \ -orient vertical \ -from $CENTmax -to $CENTmin \ -resolution $resolution \ -digits $digits \ -length $scaleLenPx \ -variable VARcent \ -font fontTEMP_scale \ -showvalue true \ -bd $BDwidthPx_scale \ -width $scaleThickPx ## -command {temperature_update} .fRsliders.fRcent.scale set $VARcent ##+################################################# ## Pack the widgets in the frame '.fRsliders.fRcent'. ##+################################################# pack .fRsliders.fRcent.label \ -side top \ -anchor nw \ -fill none \ -expand 0 pack .fRsliders.fRcent.scale \ -side top \ -anchor nw \ -fill y \ -expand 1 ##+######################################################## ## IN THE 'fRsliders.fRkelv' frame -- DEFINE ## a LABEL widget and a SCALE widget. ## The scale is oriented vertically. ## THEN PACK THEM --- the label above the scale. ##+######################################################## ## KELVIN: label .fRsliders.fRkelv.label \ -text "$aRtext(labelSCALEkelv)" \ -font fontTEMP_label \ -width 9 \ -justify left \ -anchor w \ -relief flat \ -padx $PADXpx_label \ -pady $PADYpx_label \ -bd $BDwidthPx_label scale .fRsliders.fRkelv.scale \ -orient vertical \ -from $KELVmax -to $KELVmin \ -resolution $resolution \ -digits $digits \ -length $scaleLenPx \ -variable VARkelv \ -font fontTEMP_scale \ -showvalue true \ -bd $BDwidthPx_scale \ -width $scaleThickPx ## -command {temperature_update} .fRsliders.fRkelv.scale set $VARkelv ##+################################################# ## Pack the widgets in the frame '.fRsliders.fRkelv'. ##+################################################# pack .fRsliders.fRkelv.label \ -side top \ -anchor nw \ -fill none \ -expand 0 pack .fRsliders.fRkelv.scale \ -side top \ -anchor nw \ -fill y \ -expand 1 ##+####################################### ## END OF MAIN SECTION TO SETUP THE GUI. ## FRAMES AND WIDGETS ARE DEFINED. ##+####################################### ##+####################################################################### ##+####################################################################### ## BINDINGS section: 3 bindings on button1-release on the sliders (scales). ##+####################################################################### ##+####################################################################### bind .fRsliders.fRfahr.scale \ {set TYPEchanged "FAHR" ; temperature_update 0} bind .fRsliders.fRcent.scale \ {set TYPEchanged "CENT" ; temperature_update 0} bind .fRsliders.fRkelv.scale \ {set TYPEchanged "KELV" ; temperature_update 0} ##+##################################################################### ##+##################################################################### ## PROCS section: ## 'temperature_update' - called by button1-release bindings ## 'put_vars' - called by the 'UseIt' button ## 'popup_msgVarWithScroll' - called by the 'Help' button ##+##################################################################### ##+##################################################################### ##+##################################################################### ## proc 'temperature_update' ##+##################################################################### ## PURPOSE: As any of the 3 sliders is changed, set ## 1) the other 2 sliders, and ## 2) update the text widgets that hold the temperature in 3 ## different units, in the 'fRbuttons' frame. ## 3) update the text in the label of the 'fRinfo' frame. ## 4) Reset the color-palette of the window --- between ## blue and red and white --- according to the Kelvin ## value between the min and max Kelvin values. ## ## CALLED BY: button1-release on 3 scale widgets: ## - .fRsliders.fRfahr.scale ## - .fRsliders.fRcent.scale ## - .fRsliders.fRkelv.scale ##+##################################################################### proc temperature_update {x} { global TYPEchanged VARfahr VARcent VARkelv \ widthTextWidgetChars textWidgetFiller KELVmax ######################################################## ## Reset the scale values of 2 scales from another scale. ######################################################## if {"$TYPEchanged" == "FAHR"} { set VARfahr [.fRsliders.fRfahr.scale get] set VARcent [expr {5.0 * ($VARfahr - 32.0) / 9.0}] set VARkelv [expr {$VARcent + 273.15}] } if {"$TYPEchanged" == "CENT"} { set VARcent [.fRsliders.fRcent.scale get] set VARkelv [expr {$VARcent + 273.15}] set VARfahr [expr {(9.0 * $VARcent / 5.0) + 32.0}] } if {"$TYPEchanged" == "KELV"} { set VARkelv [.fRsliders.fRkelv.scale get] set VARcent [expr {$VARkelv - 273.15}] set VARfahr [expr {(9.0 * $VARcent / 5.0) + 32.0}] } ###################################################### ## Update the text numbers in the 3 text widgets. ###################################################### ## Show the current temperature in FAHRENHEIT in a small text widget. ## Right-justify the number in the text widget. .fRtexttemps.txtVARfahr delete 1.0 end .fRtexttemps.txtVARfahr insert 1.0 "$textWidgetFiller" set fmtVARfahr [format "%5.2f" $VARfahr] set insertIDX [expr {$widthTextWidgetChars - [string length "$fmtVARfahr"]}] .fRtexttemps.txtVARfahr insert 1.$insertIDX $fmtVARfahr .fRtexttemps.txtVARfahr delete 1.[expr {$insertIDX + 7}] end ## FOR TESTING: # puts "insertIDX: $insertIDX" ## Show the current temperature in CENTIGRADE in a small text widget. ## Right-justify the number in the text widget. .fRtexttemps.txtVARcent delete 1.0 end .fRtexttemps.txtVARcent insert 1.0 "$textWidgetFiller" set fmtVARcent [format "%5.2f" $VARcent] set insertIDX [expr {$widthTextWidgetChars - [string length "$fmtVARcent"]}] .fRtexttemps.txtVARcent insert 1.$insertIDX $fmtVARcent .fRtexttemps.txtVARcent delete 1.[expr {$insertIDX + 7}] end ## FOR TESTING: # puts "insertIDX: $insertIDX" ## Show the current temperature in KELVIN in a small text widget. ## Right-justify the number in the text widget. .fRtexttemps.txtVARkelv delete 1.0 end .fRtexttemps.txtVARkelv insert 1.0 "$textWidgetFiller" set fmtVARkelv [format "%5.2f" $VARkelv] set insertIDX [expr {$widthTextWidgetChars - [string length "$fmtVARkelv"]}] .fRtexttemps.txtVARkelv insert 1.$insertIDX $fmtVARkelv .fRtexttemps.txtVARkelv delete 1.[expr {$insertIDX + 7}] end ## FOR TESTING: # puts "insertIDX: $insertIDX" ###################################################### ## Update the text in the label of the 'fRinfo' frame. ###################################################### .fRinfo.labelINFO configure -text "[get_centitext]" ###################################################### ## Set a temperature color --- and use it to set ## the color of some part of the GUI --- such as the ## troughs of the scale widgets (or the color-palette ## of the entire GUI window). ## ## The color is set via the 'set_temperatureColorformat' ## proc which returns a hex-color according to the Kelvin ## value between the min and max Kelvin values. ###################################################### set hexCOLORpal [set_temperatureColor $VARkelv] # tk_setPalette $hexCOLORpal .fRsliders.fRfahr.scale configure -troughcolor $hexCOLORpal .fRsliders.fRcent.scale configure -troughcolor $hexCOLORpal .fRsliders.fRkelv.scale configure -troughcolor $hexCOLORpal } ## END of proc 'temperature_update' ##+################################################################# ## PROCEDURE -- set_temperatureColor ## ## PURPOSE: Returns a hex-color according to the Kelvin ## value between the min and max Kelvin values. ## ## METHOD: The goal of the technique used here is to ## basically go from blue to red (and then white) ## as the Kelvin number goes from 0 to KELVmax. ## In other words, go from cold-blue to red-hot ## and white-hot. ## ## If a Tcl-Tk coder wanted, they could change ## the interpolation technique used --- and ## the color spectrum used. ## ## CALLED BY: the 'temperature_update' proc ##+################################################################ proc set_temperatureColor {VARkelv} { global KELVmax if {0} { ###################################################### ## COLOR-SETTING METHOD 1: ## We will set the color according to VARkelv in 2 ranges: ## - between 0 and about 373 (100+273) - (blue to red) ## - between about 373 and KELVmax - (red to white). ## ##------------------------------------------------------ ## For VARkelv between 0 and about 273+100=373 (boiling water): ## ## We make the BLUE component to go from 255 to 0 as ## VARkelv goes from 0 to 373 ## and ## we make the RED component to go from 0 to 255 as ## VARkelv goes from 0 to 373. ## (We keep the GREEN component fixed near zero as ## VARkelv is between 0 and 373.) ## ##------------------------------------ ## For VARkelv between 373 and KELVmax: ## ## We keep the RED component at 255 ## and ## we make the GREEN and BLUE components go from ## (near) 0 to 255 as VARkelv goes from 373 to KELVmax. ###################################################### # set midHOTkelv 373 set midHOTkelv 473 if {$VARkelv < $midHOTkelv} { set Rpal255 [expr {int(255 * $VARkelv / $midHOTkelv)}] set Gpal255 0 # set Gpal255 50 set Bpal255 [expr {int(255 * ($midHOTkelv - $VARkelv) / $midHOTkelv)}] } else { set Rpal255 255 set Gpal255 [expr {int(255 * ($VARkelv - $midHOTkelv) / $KELVmax)}] set Bpal255 $Gpal255 } } ## END OF if {0/1} section, for color-setting method 1 if {1} { ###################################################### ## COLOR-SETTING METHOD 2: ## We will set the color according to VARkelv in 3 ranges: ## - between 0 and about 373 (100+273) - (blue to red), ## - between about 373 and about 2000 - (red to yellow), ## - between about 2000 and KELVmax - (yellow to white). ## ##------------------------------------------ ## For VARkelv between 0 and REDkelv (~473): ## ## We make the BLUE component to go from 255 to 0 as ## VARkelv goes from 0 to REDkelv ## and ## we make the RED component to go from 0 to 255 as ## VARkelv goes from 0 to REDkelv. ## (We keep the GREEN component fixed near zero as ## VARkelv is between 0 and 373.) ## ##-------------------------------------------- ## For VARkelv between REDkelv and YELLOWkelv (~2000): ## ## We keep the BLUE component at 0 and keep RED at 255 as ## we make the GREEN component go from 0 to 255 while ## VARkelv goes from REDkelv to YELLOWkelv. ## ##-------------------------------------------- ## For VARkelv between YELLOWkelv and KELVmax: ## ## We keep the RED component at 255 and the GREEN component ## at 255 as we make the BLUE component go from ## 0 to 255 as VARkelv goes from YELLOWkelv to KELVmax. ###################################################### set REDkelv 473 # set YELLOWkelv 1000 set YELLOWkelv [expr {int($KELVmax/2)}] set REDtoYELLOW [expr {$YELLOWkelv - $REDkelv}] set YELLOWtoMAX [expr {$KELVmax - $YELLOWkelv}] if {$VARkelv < $REDkelv} { set Rpal255 [expr {int(255 * $VARkelv / $REDkelv)}] set Gpal255 0 # set Gpal255 50 set Bpal255 [expr {int(255 * ($REDkelv - $VARkelv) / $REDkelv)}] } elseif {$VARkelv >= $REDkelv && $VARkelv <= $YELLOWkelv} { set Rpal255 255 set Gpal255 [expr {int(255 * ($VARkelv - $REDkelv) / $REDtoYELLOW)}] set Bpal255 0 } else { set Rpal255 255 set Gpal255 255 set Bpal255 [expr {int(255 * ($VARkelv - $YELLOWkelv) / $YELLOWtoMAX)}] } } ## END OF if {0/1} section, for color-setting method 2 return [format "#%02X%02X%02X" $Rpal255 $Gpal255 $Bpal255] } ## END of proc 'set_temperatureColor' ##+################################################################# ## PROCEDURE -- get_centitext ## ## PURPOSE: Update the text in the label of the 'fRinfo' frame ## with some temperature info related to the temperature ## in the variable VARcent. ## ## CALLED BY: the 'temperature_update' proc ##+################################################################ proc get_centitext {} { global LISTcentipairs aRcentitext VARcent ## FOR TESTING: (temporarily disable this proc) # return "This is a test." ############################################################### ## Get the 'centipair' of list 'LISTcentipairs' that 'embraces' ## the current value of VARcent --- and use that 'pair index' ## to get a text string from array 'aRcentipairs'. ############################################################### ## It would be more efficient to do some sort of binary ## search in the pairs-list, but, for now, we simply do ## a linear-search from one end of the list to the other. ############################################################### foreach pair $LISTcentipairs { foreach {min max} $pair {break} if {$VARcent >= $min && $VARcent <= $max} { return "$aRcentitext($min,$max)" } } ## END OF foreach pair ... } ## END of proc 'get_centitext' ##+##################################################################### ## PROCEDURE -- put_vars ## ## PURPOSE: Puts a string containing the 3 temperatures ## (VARfahr, VARcent, VARkelv) ## to standard output. Then exits this GUI. ## ## Called by: button .fRbuttons.buttOK ##+##################################################################### proc put_vars { } { global VARfahr VARcent VARkelv puts "$VARfahr $VARcent $VARkelv" exit } ## END of proc 'puts_vars' ##+######################################################################## ## PROC 'popup_msgVarWithScroll' ##+######################################################################## ## PURPOSE: Report help or error conditions to the user. ## ## We do not use focus,grab,tkwait in this proc, ## because we use it to show help when the GUI is idle, ## and we may want the user to be able to keep the Help ## window open while doing some other things with the GUI ## such as putting a filename in the filename entry field ## or clicking on a radiobutton. ## ## For a similar proc with focus-grab-tkwait added, ## see the proc 'popup_msgVarWithScroll_wait' in a ## 3DterrainGeneratorExaminer Tk script. ## ## REFERENCE: page 602 of 'Practical Programming in Tcl and Tk', ## 4th edition, by Welch, Jones, Hobbs. ## ## ARGUMENTS: A toplevel frame name (such as .fRhelp or .fRerrmsg) ## and a variable holding text (many lines, if needed). ## ## CALLED BY: 'help' button ##+######################################################################## ## To have more control over the formatting of the message (esp. ## words per line), we use this 'toplevel-text' method, ## rather than the 'tk_dialog' method -- like on page 574 of the book ## by Hattie Schroeder & Mike Doyel,'Interactive Web Applications ## with Tcl/Tk', Appendix A "ED, the Tcl Code Editor". ##+######################################################################## proc popup_msgVarWithScroll { toplevName VARtext } { ## global fontTEMP_text fontTEMP_button ;# Not needed. 'wish' makes this global. ## global env ;# Could be used to personalize the window title. ## Using the 'bell' would probably be annoying, if it worked. # bell # bell ################################################# ## Set VARwidth & VARheight from $VARtext. ################################################# ## To get VARheight, ## split at '\n' (newlines) and count 'lines'. ################################################# set VARlist [ split $VARtext "\n" ] ## For testing: # puts "VARlist: $VARlist" set VARheight [ llength $VARlist ] ## For testing: # puts "VARheight: $VARheight" ################################################# ## To get VARwidth, ## loop through the 'lines' getting length ## of each; save max. ################################################# set VARwidth 0 ############################################# ## LOOK AT EACH LINE IN THE LIST. ############################################# foreach line $VARlist { ############################################# ## Get the length of the line. ############################################# set LINEwidth [ string length $line ] if { $LINEwidth > $VARwidth } { set VARwidth $LINEwidth } } ## END OF foreach line $VARlist ## For testing: # puts "VARwidth: $VARwidth" ############################################################### ## NOTE: VARwidth works for a fixed-width font used for the ## text widget ... BUT the programmer may need to be ## careful that the contents of VARtext are all ## countable characters by the 'string length' command. ############################################################### ##################################### ## SETUP 'TOP LEVEL' HELP WINDOW. ##################################### catch {destroy $toplevName} toplevel $toplevName # wm geometry $toplevName 600x400+100+50 wm geometry $toplevName +100+50 wm title $toplevName "Note" # wm title $toplevName "Note to $env(USER)" wm iconname $toplevName "Note" ##################################### ## In the frame '$toplevName' - ## DEFINE THE TEXT WIDGET and ## its two scrollbars --- and ## DEFINE an OK BUTTON widget. ##################################### if {$VARheight > 10} { text $toplevName.text \ -wrap none \ -font fontTEMP_text \ -width $VARwidth \ -height $VARheight \ -bg "#f0f0f0" \ -fg "#000000" \ -relief raised \ -bd 2 \ -yscrollcommand "$toplevName.scrolly set" \ -xscrollcommand "$toplevName.scrollx set" scrollbar $toplevName.scrolly \ -orient vertical \ -command "$toplevName.text yview" scrollbar $toplevName.scrollx \ -orient horizontal \ -command "$toplevName.text xview" } else { text $toplevName.text \ -wrap none \ -font fontTEMP_text \ -width $VARwidth \ -height $VARheight \ -bg "#f0f0f0" \ -fg "#000000" \ -relief raised \ -bd 2 } button $toplevName.butt \ -text "OK" \ -font fontTEMP_button \ -command "destroy $toplevName" ############################################### ## PACK *ALL* the widgets in frame '$toplevName'. ############################################### ## Pack the bottom button BEFORE the ## bottom x-scrollbar widget, pack $toplevName.butt \ -side bottom \ -anchor center \ -fill none \ -expand 0 if {$VARheight > 10} { ## Pack the scrollbars BEFORE the text widget, ## so that the text does not monopolize the space. pack $toplevName.scrolly \ -side right \ -anchor center \ -fill y \ -expand 0 ## DO NOT USE '-expand 1' HERE on the Y-scrollbar. ## THAT ALLOWS Y-SCROLLBAR TO EXPAND AND PUTS ## BLANK SPACE BETWEEN Y-SCROLLBAR & THE TEXT AREA. pack $toplevName.scrollx \ -side bottom \ -anchor center \ -fill x \ -expand 0 ## DO NOT USE '-expand 1' HERE on the X-scrollbar. ## THAT KEEPS THE TEXT AREA FROM EXPANDING. pack $toplevName.text \ -side top \ -anchor center \ -fill both \ -expand 1 } else { pack $toplevName.text \ -side top \ -anchor center \ -fill both \ -expand 1 } ##################################### ## LOAD MSG INTO TEXT WIDGET. ##################################### ## $toplevName.text delete 1.0 end $toplevName.text insert end $VARtext $toplevName.text configure -state disabled } ## END OF PROC 'popup_msgVarWithScroll' ##+############################################### ## END OF PROCS SECTION. ##+############################################### ## Setting of HELPtext variable follows. ##+############################################### set HELPtext "\ *** HELP for this tkTemperature-Convert-Select GUI **** This TkGUI script provides a GUI for showing temperatures between absolute zero and several thousand degrees --- in three different units: - Fahrenheit - Centigrade - Kelvin. This utility is a 'converter-selector' in the sense that 1) You can convert a number from any of the three temperature scales to the other two by simply moving any one of the three 'slider buttons'. 2) You can click on the 'UseIt' button to return the current 3 numbers --- for a temperature in Fahrenheit, Centigrade, and Kelvin --- to a calling application, such as a shell script or another Tk script. **************************** THE CONVERSION FUNCTIONALITY of this utility: The 3 different temperature values (in different units) are shown (and selected for conversion) via 3 'sliders' of 3 Tk 'scale' widgets. These 3 different (corresponding) temperature numbers are also shown in 3 'text' widgets, several characters wide --- from which a user can copy-and-paste the numbers from this GUI window to some other window. For any 'slider' change, this GUI script IMMEDIATELY (when the mouse button is released) updates the location of the other 2 'sliders'. The 3 text widgets, showing the temperature in the 3 different units, are also 'immediately' updated whenever any one of the 3 scale widget 'sliders' are changed. *************************** FINE CONTROL OF THE SLIDERS: Most people know that you can drag the sliders by clicking on a 'slider button' with mouse-button1 and dragging the slider button. This is a rather coarse way of moving the slider button. It is not so obvious that the Tk scale widget also allows you to move the 'slider button' by clicking in the 'trough' on EITHER SIDE of the slider button. By repeated clicking in the trough, the slider can be advanced one scale resolution-unit per click. Furthermore, one can RAPIDLY move the slider button, in a fairly well-controlled fashion, by clicking in the 'trough' and HOLDING down the mouse button. The slider moves one resolution unit at a time UNTIL the mouse button is RELEASED. ************************** THE SELECTOR FUNCTIONALITY: By clicking on a 'UseIt' button on the GUI, this script returns a string containing the current temperature (in the 3 different units) to a calling script/application. When using this script in another script/program, this script will accept a temperature (in Centigrade) as an argument which is used to initialize the - setting of the 3 'sliders', and - the numbers shown in the 3 small text widgets. ************************* SOME USES of this utility: 1) Useful for helping math-science students get a visual 'feel' for the relation between Fahrenheit, Centigrade, and Kelvin. 2) Also could be useful to programmers (for example, Tcl-Tk programmers) for determining temperatures (example: in Centigrade) to be used in various (Tcl-Tk) apps. 3) IN A SHELL SCRIPT or ANOTHER TK SCRIPT, this Tk script can ACT AS AN TEMPERATURE SELECTOR by passing the current temperature (in the 3 different units) to stdout, when the 'UseIt' button is clicked. Example output string: 32.0 0 273.0 (Fahrenheit,Centigrade,Kelvin) *************************** SOME REFERENCE TEMPERATURES: The following table gives some 'temperature transition points', in degrees Centigrade, for various materials. --------------------------------------------------- The string 'solid <-> liquid' can be read 'changes between solid and liquid'. This can mean 'melts' or 'freezes' depending on whether you think of the temperature increasing or decreasing (heat being added/removed), respectively. So 'solid <-> liquid' can also be thought of as 'melts/freezes' --- but it may be strange to think of freezing at high temperatures. ---------------------------------------------------- The string 'liquid <-> gas' can be read 'changes between liquid and gas'. This can mean 'boils' or 'condenses' depending on whether you think of the temperature increasing or decreasing (heat being added/removed), respectively. So 'liquid <-> gas' can also be thought of as 'boils/condenses'. ---------------------------------------------------- Temperature in Centigrade Phenomenon (at 'atmospheric pressure') ----------------- ----------------------------------------- at 3422 C tungsten solid <-> liquid (melts/freezes) at 3287 C titanium liquid <-> gas (boils/condenses) at 2807 C gold liquid <-> gas (boils/condenses) at 1772 C platinum solid <-> liquid (melts/freezes) at 1667 C titanium solid <-> liquid (melts/freezes) at 1535 C iron solid <-> liquid (melts/freezes) at 1400 to 1500 C steel solid <-> liquid (melts/freezes) at 1250 to 1450 C porcelain solid <-> liquid (melts/freezes) at 1083.4 C copper solid <-> liquid (melts/freezes) at 1064.43 C gold solid <-> liquid (melts/freezes) at ~600 to ~1400 C clay glazes solid <-> liquid (melts/freezes) at 900 to 1000 C brass(copper+zinc) solid <-> liquid (melts/freezes) at 881 C sodium liquid <-> gas (boils/condenses) at 766 C potassium liquid <-> gas (boils/condenses) at 444.6 C sulfur liquid <-> gas (boils/condenses) at 419.58 C zinc solid <-> liquid (melts/freezes) at 113 to 120 C sulfur solid <-> liquid (melts/freezes) at 100.0 C water liquid <-> gas (boils/condenses) at 97.8 C sodium solid <-> liquid (melts/freezes) at 63.2 C potassium solid <-> liquid (melts/freezes) 37 C is normal human body temperature about 25 C is 'room temperature' at 0.0 C ice/water/H2O solid <-> liquid (melts/freezes) at -56.6 C carbon-dioxide/CO2 liquid <-> gas (boils/condenses) at -78.5 C carbon-dioxide/CO2 solid <-> liquid (melts/freezes) at -152.3 C krypton liquid <-> gas (boils/condenses) at -156.6 C krypton solid <-> liquid (melts/freezes) at -182.9 C oxygen/O2 liquid <-> gas (boils/condenses) at -195.8 C nitrogen/N2 liquid <-> gas (boils/condenses) at -209.9 C nitrogen/N2 solid <-> liquid (melts/freezes) at -218.4 C oxygen/O2 solid <-> liquid (melts/freezes) at -259 C hydrogen/H2 solid <-> liquid (melts/freezes) -273.15 C is absolute zero Some 'freaks': Arsenic, dry ice (solid carbon dioxide), and iodine go directly from solid to gas (sublimation) at normal atmospheric pressure. *********** REFERENCES: Some interesting information on temperatures can be seen at http://en.wikipedia.org/wiki/Absolute_zero http://en.wikipedia.org/wiki/Absolute_hot and information on boiling points and melting points can be seen at pages like http://en.wikipedia.org/wiki/Tungsten http://en.wikipedia.org/wiki/Carbon_dioxide etc. " ##+############################################### ## ADDITONAL GUI INITIALIZATION (if any) FOLLOWS. ##+############################################### ## See the setting of initial temps at the argv section ## near the top of this code --- near the frame definitions. ## (We allow the initial temperature to be passed as an ## argument to this script.) ##+######################################################### ##+######################################################### ## Set the list 'LISTcentipairs' and the array 'aRcentitext' ## for use by the 'get_centitext' proc. ##+######################################################### ## The centigrade-temperature-pairs should cover the ## entire range --- from -300 to 4000, say --- with no gaps. ## ## That is, the left-number of one pair should match the ## right-number of the pair below, in this list. ## ## So you can add more entries to the list by 'splitting' ## a pair of numbers. For example: The statments ## ## lappend LISTcentipairs "3300 4000" ## set aRcentitext(3300,4000) "tungsten melts at 3410 C" ## ## lappend LISTcentipairs "3000 3300" ## set aRcentitext(3000,3300) "titanium boils at 3287 C" ## ## could have been generated from the statement-pair ## ## lappend LISTcentipairs "3000 4000" ## set aRcentitext(3000,4000) "tungsten melts at 3410 C" ## ## by inserting the new information about the titanium ## boiling point --- by adding the number 3300 between ## 3000 and 4000. ##+########################################################## set maxInfoWidthChars 0 lappend LISTcentipairs "3300 4000" set aRcentitext(3300,4000) "At 3422 C, tungsten melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(3300,4000)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "3000 3300" set aRcentitext(3000,3300) "At 3287 C, titanium boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(3000,3300)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "2000 3000" set aRcentitext(2000,3000) "At 2807 C, gold boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(2000,3000)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1700 2000" set aRcentitext(1700,2000) "At 1772 C, platinum melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1700,2000)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1600 1700" set aRcentitext(1600,1700) "At 1667 C, titanium melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1600,1700)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1500 1600" set aRcentitext(1500,1600) "At 1535 C, iron melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1500,1600)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1400 1500" set aRcentitext(1400,1500) "At 1400 to 1500 C, steels melt/freeze (change between solid and liquid)." set tempWidthChars [string length "$aRcentitext(3300,4000)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1200 1400" set aRcentitext(1200,1400) "At 1250 to 1450 C, porcelain melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1200,1400)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1080 1200" set aRcentitext(1080,1200) "At 1083.4 C, copper melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1080,1200)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "1000 1080" set aRcentitext(1000,1080) "At 1064.43 C, gold melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(1000,1080)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "950 1000" set aRcentitext(950,1000) "At about 600 to 1400 C, clay glazes melt/freeze (change between solid and liquid)." set tempWidthChars [string length "$aRcentitext(950,1000)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "900 950" set aRcentitext(900,950) "At 900 to 1000 C, brass(copper+zinc) melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(900,950)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "800 900" set aRcentitext(800,900) "At 881 C, sodium boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(800,900)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "600 800" set aRcentitext(600,800) "At 766 C, potassium boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(600,800)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "430 600" set aRcentitext(430,600) "At 444.6 C, sulfur boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(430,600)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "300 430" set aRcentitext(300,430) "At 419.58 C, zinc melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(300,430)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "110 300" set aRcentitext(110,300) "At 113 to 120 C, sulfur melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(110,300)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "99 110" set aRcentitext(99,110) "At 100.0 C, water/steam/H2O boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(99,110)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "80 99" set aRcentitext(80,99) "At 97.8 C, sodium melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(80,99)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "50 80" set aRcentitext(50,80) "At 63.2 C, potassium melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(50,80)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "30 50" set aRcentitext(30,50) "37 C is normal human body temperature." set tempWidthChars [string length "$aRcentitext(30,50)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "20 30" set aRcentitext(20,30) "About 25 C is 'room temperature'." set tempWidthChars [string length "$aRcentitext(20,30)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-40 20" set aRcentitext(-40,20) "At 0.0 C, ice/water/H2O melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(-40,20)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-70 -40" set aRcentitext(-70,-40) "At -56.6 C, carbon-dioxide/CO2 boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(-70,-40)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-120 -70" set aRcentitext(-120,-70) "At -78.5 C, carbon-dioxide/CO2 melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(-120,-70)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-155 -120" set aRcentitext(-155,-120) "At -152.3 C, krypton boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(-155,-120)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-170 -155" set aRcentitext(-170,-155) "At -156.6 C, krypton melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(-170,-155)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-190 -170" set aRcentitext(-190,-170) "At -182.9 C, oxygen/O2 boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(-190,-170)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-200 -190" set aRcentitext(-200,-190) "At -195.8 C, nitrogen/N2 boils/condenses (changes between liquid and gas)." set tempWidthChars [string length "$aRcentitext(-200,-190)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-215 -200" set aRcentitext(-215,-200) "At -209.9 C, nitrogen/N2 melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(-215,-200)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-240 -215" set aRcentitext(-240,-215) "At -218.4 C, oxygen/O2 melts/freezes (changes between solid and liquid)." set tempWidthChars [string length "$aRcentitext(-240,-215)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-270 -240" set aRcentitext(-270,-240) "At -259 C, hydrogen/H2 melts/freezes (changes between solid and liquid). " set tempWidthChars [string length "$aRcentitext(-270,-240)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} lappend LISTcentipairs "-300 -270" set aRcentitext(-300,-270) "-273.15 C is absolute zero." set tempWidthChars [string length "$aRcentitext(-300,-270)"] if {$tempWidthChars > $maxInfoWidthChars} {set maxInfoWidthChars $tempWidthChars} ## FOR TESTING: # puts "LISTcentipairs: $LISTcentipairs" # puts "aRcentitext(-300,-270): $aRcentitext(-300,-270)" .fRinfo.labelINFO configure -width $maxInfoWidthChars ##+######################################## ## Initialize the scale widgets, by calling ## the 'temperature_update' proc. ##+######################################## set TYPEchanged "CENT" temperature_update $VARcent