FE 'tkGooie' Utilities

'SELECTORtools' group

tkAngle ConvertSelect

(an angle convert
and/or select utility)

(FE = Freedom Environment)

GUI interface to select
an angle and display it
as radians, degrees, or
percent of circumference of
a circle, on 3 'scale' widgets.
The GUI includes a
Tk 'canvas' widget
on which to display
the user-specified
Large, hi-def image
is below.

FE Home Page > FE Downloads Page >

FE 'tkGooies' Description Page >

FE 'tkGooies' 'SELECTORtools' Menu >

tkGooie code Page

INTRODUCTION to Tcl-Tk script

I was reading a math book recently (in 2013) --- 'A History of Pi' by Petr Beckmann.

There was a presentation of a formula (and geometry) for estimating the length of an arc on a circle by getting the length of a straight line segment, constructed nearby.

This got me to thinking about converting angles from one unit to another --- radians or degrees to distances.

It then hit me that my color-selector GUI (with 3 'slider buttons') --- whose code is available at a page titled

'A non-obfuscated color selector GUI'

--- could easily be converted into an angle-converter utility.

And the 'color swatch' on that utility (which was done with a 'frame' widget) could be changed to a 'canvas' widget, on which a representation of the current angle could be drawn.

There would need to be a big difference between the 'color selector' GUI and the 'angle converter' GUI --- namely, the 3 RGB sliders on the 'color selector' GUI needed to move independently of each other.

For the 'angle 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 (containing the value of an angle in 3 different units) changed, the other 2 variables were changed correspondingly.

So I set to work converting the code of the color-selector GUI to an angle-converter GUI, and I ended up with the GUI seen in the following image.

This image does not do justice to the immediacy of the changes. Whenever ONE of the 'sliders' is moved:

  • the other TWO sliders move

  • the angle depicted in the circle on the canvas changes

  • the 3 text areas change to present the current 3 values for the angle (available for copy-paste into another window on the desktop)

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

Here is most of the Help:

HELP for this
'tkAngle-Convert-Select' GUI utility
for angles in radians, degrees, or

This Tk script provides a GUI for showing angles between zero and 360 degrees in three different units:

  • degrees
  • radians
  • percent of the circumference of a circle.

These 3 different units are shown via 3 'sliders' of 3 Tk 'scale' widgets.

The 'scale' widgets allow for selecting the angle in one 'unit of measure' --- for conversion to the other 2 units.

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, such as a text-editor window.

For any 'slider' change, this GUI script IMMEDIATELY updates the location of the other 2 'sliders' --- and the current angle is depicted on a circle drawn in a 'canvas' wdiget in a corner of the GUI window (covering about 20% of the window).

The 3 text widgets, that show the angle in the 3 different units, are also IMMEDIATELY updated whenever any one of the 3 scale widget 'sliders' is changed.

By clicking on a 'UseIt' button on the GUI, this script returns a string containing the current angle (in the 3 different units) to a calling script/application.



This script will accept an angle (in degrees) which is used to initialize the

  • setting of the 3 'sliders'

  • the numbers shown in the 3 small text widgets

  • the display of an angle in a circle on the canvas widget.

The angle can be passed to the script as an argument --- OR, if some 'catch' statements in the script are de-commented --- the angle can be passed as an environment variable.



It is typically not obvious (esp. to a user who has not used the Tk scale widget before) that one can easily advance the 'slider' one resolution-unit at a time.

You can mouse-click ON EITHER SIDE OF the slider 'button' to advance the slider one resolution-unit per click.

Simply click repeatedly to adjust the slider to a specific value.

AND, by clicking on either side and HOLDING DOWN, the slider will rapidly advance one resolution-unit at a time UNTIL the mouse-button is RELEASED.

SOME USES of this utility:

  1. Useful for helping math-science students get a visual 'feel' for the relation between radians and degrees and the distance around the circumference of a circle.

  2. Also could be useful for programmers (example: Tcl-Tk programmers) for determining angles (example: radians) to be used in various Tcl-Tk apps --- example: Tk apps doing 'create arc' commands on a Tk 'canvas'.

  3. IN A SHELL SCRIPT OR ANOTHER TK SCRIPT, this Tk script can ACT AS AN ANGLE SELECTOR by passing the current angle (in the 3 different units) to 'stdout', when the 'UseIt' button is clicked.

    Example output string:

    180.0   3.14159   0.5

    (When the 'Cancel' button is clicked, the GUI is closed WITHOUT sending a text string to 'stdout'.)

The user can set up this script as an icon on a desktop so that the GUI can be started up by a click (or two) on the icon.


Below, I provide the Tk script code for this 'tkAngle-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

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, like for the 'color selector' GUI on which it was based, I have chosen to make the window stay at the same size that it takes when it is initially 'packed'.

However, one could comment the statement

wm resizable . 0 0

and activate the statement

wm minsize . $minWinWidthPx $minWinHeightPx

and the statements that set the min-width and min-height values.


I have used some 'well-behaved' choices for the 'pack' parameters.

In particular ...

The labels and buttons and scales are set to stay fixed in size and relative-location as the window is re-sized.

But it might be nice to make the canvas increase in size if the window is increased in size.

Currently, the calculation for putting the circle and filled-angle on the canvas may not scale properly as window size is changed.

If you want to make 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 --- and adjust the calulations for drawing the circle and filled-angle, if necessary.


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.

   'angle_update'           - called once initially, and then whenever a slider is moved

   'draw_circle'            - called once to draw the circle

   'redraw_angle'           - called by 'angle_update'

   'put_vars'               - called when the 'UseIt' button is clicked

   'popup_msgVarWithScroll' - called when the 'Help' button is clicked

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 cats-looking-bored --- and then going crazy.

The Tcl-Tk script CODE

Here is a link to CODE for the script

'tkAngleConvertSelect_ radians-degrees-percents.tk'.


I do not have any plans for further enhancements for this GUI, but a 'ColorMe' button could be added to this GUI --- like I did for a font-selector GUI whose code I contributed to wiki.tcl.tk at a page originally titled

"YAFSG - Yet Another Font Selector GUI"

and in a 'tkPointerSettings' GUI whose code I contributed to wiki.tcl.tk at 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 available at

A non-obfuscated color selector GUI,

to change the color of this tkAngle-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.


Once in a while, I see questions in forums like 'how can i make several scale widgets move in unison?'.

Well, this Tk script provides some code that answers that particular question --- in detail, with a full example --- not a 'snippet'.

I sometimes wonder how many lines of code it would have taken in C or C++ with a widgets-library like Qt or Gtk or wxWidgets to do something like getting scale widgets to move in unison.

But I don't wonder for long.

Back to Tcl-Tk.

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 2013 --- and posted 2013 Aug 12 at http://wiki.tcl.tk/38458.

This FE web page was created 2014 May 07.
(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.