FE 'tkGooie' Utilities
(an angle convert
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
Large, hi-def image
FE Home Page >
FE Downloads Page >
FE 'tkGooies' Description Page >
FE 'tkGooies' 'SELECTORtools' Menu >
tkGooie code Page
INTRODUCTION to Tcl-Tk script
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
--- 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 'Help' button on the GUI provides pretty complete and detailed help for using the GUI.
Here is most of the Help:
HELP for this
This Tk script provides a GUI for showing angles between zero and 360 degrees in three different units:
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.
INITIALIZING THE ANGLE:
This script will accept an angle (in degrees) which is used to initialize the
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.
FINE ADJUSTMENTS OF THE SCALES:
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:
DESCRIPTION OF THE CODE
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:
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
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
SOME POTENTIAL ENHANCEMENTS:
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
and in a 'tkPointerSettings' GUI whose code I contributed to wiki.tcl.tk at a page titled
With a 'ColorMe' button, the user could easily use a color selector, like the one whose code is available at
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'.
But I don't wonder for long.
Back to Tcl-Tk.
Bottom of this web page for
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.
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.