FE 'tkGooie' Utilities

'SELECTORtools' group


(a temperature convert
and/or select utility)

(FE = Freedom Environment)

GUI interface to convert
among Fahrenheit,
Centigrade, and Kelvin
using vertical
'scale' widgets.

Large, hi-res images
are below.

FE Home Page > FE Downloads Page >

FE 'tkGooies' Description Page >

FE 'tkGooies' 'SELECTORtools' Page >

tkGooie code Page

INTRODUCTION to Tcl-Tk script

In the past year (2013), I posted some 'converter-selector' Tk GUI utilities on pages at wiki.tcl.tk:

  1. an angle converter-selector utility --- at wiki.tcl.tk in a page titled

    'tkAngle-Convert-Select - radians, degrees, percents-of-circumference-of-circle'

  2. a velocity converter-selector utility --- at wiki.tcl.tk in a page titled

    'tkSpeedGun-Convert-Select - kilometers/hr, miles/hr, lightyears/billion-years'.

I based those GUI's on my color-selector GUI (with 3 'slider buttons') --- whose code is available on this FE web site at a page titled

'A non-obfuscated color selector GUI'.

However, on the color-selector GUI, the 3 slider-buttons were moved independently of each other.

For the 'angle converter' GUI and for the 'speed-gun converter' GUI, the 3 sliders would need to move together.

The Tk 'scale' widget handles that nicely.

In Tk, a variable is associated with each 'slider', and any time the value of that variable changes, the slider moves to reflect the changed value.

I just needed to make sure that when any of the 3 variables changed, the other 2 variables were changed correspondingly.


I have found (occasionally) that I have need for OTHER types of converters:

  • for temperature (Fahrenheit, Centigrade, Kelvin)

  • for volume (tablespoons, cups, quarts, liters, gallons, barrels, etc.),

  • for distance (inches, centimeters, meters, yards, miles, kilometers, light-years, etc.)

On this page, I present the code for a temperature converter-selector utility.



On the several converter-selector utilities that I have written so far, the 3 scale widgets on the GUI's were oriented horizontally.

However, for the temperature converter GUI, it seemed appropriate to orient the 3 scale widgets vertically --- like 3 thermometers.



The converter would seem rather plain (and rather uninformative) if just the 3 scales were provided --- with a display of a temperature in the 3 different units (Fahrenheit, Centigrade, and Kelvin).

So to provide some perspective, I decided to show on the GUI a line of text --- with information corresponding to the current temperature setting.

The text indicates boiling or melting point information for a material --- at a temperature in the 'neighborhood' of the current temperature setting of the scale widgets.

And to get an overview of the range of melting and boiling points of various materials, throughout the temperature range of the scale widgets, the 'Help' button on the GUI provides text which includes a table of temperatures that are melting and boiling points of various materials (fundamental elements, molecules, mixtures of molecules --- such as copper, carbon-dioxide, brass, various steels, and glazes).

The user can click on the 'Help' button to see that overview of 'phenomena' that occur over a wide temperature range.



To further liven up the GUI, I have provided some dynamic color change:

The color of the 'troughs' of the scale widgets change as the temperature is changed.

    (I initially changed the entire color palette of the GUI as the temperature was changed, but that seemed like too much color change.

    It is easy to comment and un-comment a few statements in the code below to see what that more extensive color-change looks like.)

There are various ways one could implement the color change:

  1. A 2-phase change --- say from 'blue(cold)-to-red(hot)' as temperature goes from absolute zero to about twice the boiling point of water.

    Then from 'red(hot)-to-white(hot)' from boiling to the top of the temperature scales.

  2. A 3-phase change --- say from 'blue-to-red' as temperature goes from absolute zero to about twice the boiling point of water.

    Then from 'red-to-yellow' from that point to about 2000 degrees.

    Then from 'yellow-to-white' from about 2000 degrees to the top of the temperature scales.


So I set to work making a GUI with these features, and I ended up with the GUI seen in the following image.

Whenever ONE of the 'sliders' is moved with mouse-button1 :

  • the other TWO sliders move
    (showing the converted values)

  • 3 'text' widgets (on a line above the vertical 'scale' widgets) change to present the current 3 values for the temperature.

    The 3 text' widgets make the numbers available for copy-paste into another window on the desktop, such as a text-editor window.

The new values show (and the colors change) as soon as mouse-button1 is released (extremely fast response).

Note that when the temperature is around 0 degrees Centigrade, a line of text (between the 3 'scale' widgets and the 3 'text' widgets) indicates that 0 Centigrade is the melting point of ice.

That text line is used to show melting or boiling point information related to the currently displayed temperature.


Below is an image in which the temperature has been increased to 1537 degrees Centigrade --- and the line of text indicates that iron melts in the neighborhood of this temperature.

In addition, I am using the 3-phase color-change described above, and the troughs of the scales have changed to a yellowish color.


The following image indicates that I have allowed the window to be resizable.

In this case, I have dragged the lower-right corner of the window to make the GUI smaller.

Furthermore, the line of text indicates that tungsten melts in the neighborhood of this temperature --- and the troughs of the scales have changed to a whitish color.

The 'Help' button on the GUI provides pretty complete and detailed help for using the GUI.

In particular, the help points out the following info --- which is in the 'HELPtext' variable of the Tcl-Tk code.

   Most people know that you can drag the sliders by clicking
   on the '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 ONE
   RESOLUTION UNIT per 'auto-click' by clicking in the trough
   and HOLDING down the mouse button. The slider moves
   one resolution unit repeatedly UNTIL the mouse button


Below, I provide the Tk script code for this 'tkTemperature-Convert-Select' utility.

I follow my usual 'canonical' structure for Tk code for this Tk script:

  0) Set general window & widget parms (win-name, win-position,
     win-color-scheme, fonts, widget-geometry-parms, win-size-control,

  1a) Define ALL frames (and sub-frames, if any).
  1b) Pack   ALL frames and sub-frames.

  2) Define & pack all widgets in the frames, frame by frame.
              Within each frame, define ALL the widgets.
              Then pack the widgets.

  3) Define keyboard and mouse/touchpad/touch-sensitive-screen action
     BINDINGS, if needed.

  4) Define PROCS, if needed.

  5) Additional GUI initialization (typically with one or more of
     the procs), if needed.

This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations.

This structure makes it easy for me to find code sections --- while generating and testing a Tk script, and when looking for code snippets to include in other scripts (code re-use).

I call your attention to step-zero.

One new thing that I have started doing recently is using a text-array variable --- named 'aRtext' --- for text in labels, buttons, and other widgets in the GUI.

This can make it easier for people to internationalize my scripts.

I will be using a text-array like this in most of my scripts in the future.

Experimenting with the GUI
--- its behavior

As in all my scripts that use the 'pack' geometry manager (which is all of my 100-plus scripts, so far), I provide the four main 'pack' parameters:

  • '-side'
  • '-anchor'
  • '-fill'
  • '-expand'

--- on all of the 'pack' commands for the frames and widgets.

That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.

In this particular GUI, I allowed the user to resize the window.

However, one could un-comment the statement

wm   resizable   .   0   0

and then the user would not be able to change the size of the window from its initially built size.

With the window resizable, you can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want as the window is resized.


Additional experimentation with the GUI
--- its appearance:

You might want to change the fonts used for the various GUI widgets.

For example, you could change '-weight' from 'bold' to 'normal' --- or '-slant' from 'roman' to 'italic'.

Or change font families.

    In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing.

I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding.

And I have included the '-relief' parameter on the definitions of frames and widgets.

Feel free to experiment with those 'appearance' parameters as well.

Some features in the code

There are plenty of comments in the code, to describe what most of the code-sections are doing.

You can look at the top of the PROCS section of the code to see a list of the procs used in this script, along with brief descriptions of how they are called and what they do.

The main procs are as follows.

   '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

The main proc is the 'temperature_update' proc.

As any of the 3 sliders is changed, the 'temperature_update' proc

  • sets the value for the other 2 sliders

  • updates the small text widgets that hold the temperature in 3 different units

  • calls 'get_centitext' to set the melting/boiling info-line on the GUI --- according to the current Centigrade temperature

  • calls 'set_temperatureColor' to set the color of some parts of the GUI --- like the troughs of the 'scale' widgets.

Comments in the Code

It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this.

Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch videos of volcanos, wildfires, melting glaciers, people in burning clothes, and other elevated-temperature phenomena.

Potential Tclers:

While Earth roasts, try installing-running-enhancing the following Tcl-Tk code.

The Tcl-Tk script CODE

Here is a link to CODE for the script



Some might want another scale widget on the GUI --- for degrees Rankine, which is to Fahrenheit as Kelvin is to Centigrade.


I probably should add a 'ColorMe' button to this GUI --- like I did for a font-selector GUI whose code I contributed at wiki.tcl.tk on a page titled

"YAFSG - Yet Another Font Selector GUI"

and for a 'tkPointerSettings' GUI whose code I contributed at wiki.tcl.tk on a page titled

"tkPointerSettings - a Tk GUI 'wrapper'
for the 'xinput' command"

With a 'ColorMe' button, the user could easily use a color selector, like the one whose code is provided on this FE web site in a page titled

'A non-obfuscated color selector GUI',

to change the color of this tkTemperature-Convert-Select GUI.

Instead of supplying a 'ColorMe' button to do that, I simply point out that the user can change the RGB values for the 'tk_setPalette' statement near the top of this code.


More materials and their melting and/or boiling points could be added to this GUI, in a manner that is described at the bottom of the code --- where the 'LISTcentipairs' list and 'aRcentitext' array are built.


As I was putting finishing touches on this code, I kept finding some corrections/improvements to make in the melting/boiling point information.

I have little doubt that there are some further corrections or improvements to be made.

Also, I have NOT tried to make the conversions consistently accurate to a couple of decimal places.

I have been satisfied if the conversions are correct to the nearest integer degree.

However, if others are not satisfied with that approach, this is where having Tcl-Tk script code at hand is a boon.

Simply change the code however you like.


As I have said on other code-donation pages on this FE web site ...

There's a lot to like about a utility that is 'free freedom' --- that is, no-cost and open-source so that you can modify/enhance/fix it without having to wait for someone else to do it for you (which may be never).

A BIG THANK YOU to Ousterhout for starting Tcl-Tk, and a BIG THANK YOU to the Tcl-Tk developers and maintainers who have kept the simply MAH-velous 'wish' interpreter going.

Bottom of this web page for
presenting Tcl-Tk code for
--- a utility in the FE 'tkGooies' system,
in the 'SELECTORtools' group.

To return to a previously visited web page location, click on the Back button of your web browser a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to Top of Page, above. >

Page history:

The code was created in 2014 --- and posted 2014 Jan 17 at http://wiki.tcl.tk/39229.

This FE web page was created 2014 May 17.
(as a backup and alternative to the wiki.tcl.tk page)

This page was changed 2015 Oct 05.
(Small changes.)

Page was changed 2019 Mar 07.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)

Page was changed 2019 Jul 09.
(Specified image widths in percents to size the images according to width of the browser window. Also added some web links.)

The code here MAY BECOME more 'up-to-date' than the code posted on the Tcler's Wiki ---
wiki.tcl-lang.org --- formerly wiki.tcl.tk.