Welcome to Tcl/Tk GUI Programming 
Lesson #1: installation of tools

Course content Enter chat room Send email 
to mailing list
Check calendar

JUST A REMINDER:  for those of you who have not yet received your confirmation that you have been
subscribed to the mailing list please contact us by email immediately.

In memory of Linda.  Worldwide Cancer sites here.    Canadian Cancer donations here.
 

Hint:

Once the programming tools have been downloaded these lessons are designed to be worked on offline.  For those of you with dialup Internet access  you might find it helpful to print off the page for each lesson and work from the printout. 

In this lesson you are going to learn how to download and setup the programming tools that we will be using throughout this course.
 
There are lots of different ways to program a computer.  Computers are essentially very stupid.   Even the fastest desktop computers can only understand a 100 or so commands in their microprocessor "brains".   These commands in and of themselves are very simple things like "add these two numbers", "compare these two values" or "fetch this value from memory".   How then could computers possibly appear to be so "smart"?
The simple answer is that they are able to do lots of simple things extremely quickly.   So quickly that the desktop computer that you are reading this on can easily do several million such commands every second. 
While some people still occasionally program computers by setting up these millions of microprocessor commands directly by hand you can appreciate that writing something like a computer game or wordprocessing program in this manner would be extremely laborious and tedious.  You see humans and computers don't speak the same language.
To help with this immense problem associated with programming a computer people began to invent tools called "programming languages" and other tools to translate these "human programming languages" into the language that the microprocessor understands.   There are many programming languages used to program modern computers.   The one we have chosen to use for this course goes by the name Tcl/Tk which stands for "Tool Control Language with a Tool Kit".   It is affectionately known by the 500000 or so users world wide by the name "tickle tee kay".

Tcl/Tk is a very good language to start to learn about computer programming because:

The first step: downloading all our programming tools

Our first requirement in this lesson is going to be to download the Tcl/Tk programming language and tools appropriate for the computer type we are using.     Tcl/Tk is maintained today by a company which goes by the name Active State

For those of you familiar with downloading and installing software from the Internet you can simply skip through to the link to the download location on the Tcl Developer Xchange site by clicking here.  For all the others we suggest you read this installation section.


 

Linux users:

Many Linux distributions come with Tcl/Tk already installed.

You can tell if you have Tcl/Tk on your Linux system by typing:

                            which tclsh
                            which wish

Windows users who don't want to download and install anything:

Provided your computer can be configured to boot from the CDROM drive,   you can take advantage of a technology called a LiveCD.     In this mode your computer will boot and run entirely from the CD and leave your harddrive and normal boot mode unchanged.      For more information consult the following How To.
 
 

Once you have downloaded and installed the software on your computer you might want to take a moment to create some aliases or shortcuts to the various tools we are going to be using and put those shortcut icons on your main computer desktop so that they are easily reached.    The shortcuts we will be wanting are for the following items in the Tcl/Tk tool chest: Tcl Tk Help; Wish and Tclsh.  In addition we will be needing a shortcut to our preferred text editor for future lessons.   For Windows users this will be Wordpad.  For Mac users it will be Simple Text.   Linux users have plenty to chose from.  (for hints on how to create shortcuts click here).
 

The second step: writing our very first program

At this point you should have the Tcl/Tk tools set installed on your machine and have three new icons on your desktop representing the tools we require.    You must be anxious to write your very first computer program.    We are going to be using a feature of the Tcl/Tk tools that are not available in every computer language: the ability for the program to be written and run interactively.   In other words we are going to type something and then immediately run the program.    This mode of programming is often called "interpretive mode" and it is a great way to test out simple programs and programming constructs.

The  instructions below will show a screen print off an IBM PC (the screens on other systems will look very similar).

Congratulations!  You have just written your very first Tcl/Tk program!
Feel free to experiment with the words inside the "" ... perhaps by inserting your name.    Notice that you can use the "up arrow" key to recall the previous line and make changes by using the "left or right arrow" to edit the line.

 

Explanation of the first program

To begin to understand programming languages and the Tcl/Tk language in particular we need to start by introducing some of the lingo.    Each line in our program contains what is referred to as a programming statement or statement for short.    Tcl/Tk is a particularly simple language and every statement will always have the same elements:
 
command arg1 arg2 arg3 ...

where arg stands for "argument".   Why these parameters are called arguments is beyond me ... just think of them as those things that come after the command.

In our little programming example the command was: puts.    This command is used to "put things" or "display things".

The first argument in our example was: stdout.   This is short for "standard output".   For us stdout will always mean the console screen.   One thing you will find is that programmers in general are a lazy lot.   The laziest programmers of the bunch are those who write operating systems or programming languages.   That is why we end up often with cryptic commands like "puts" and clipped arguments like "stdout" ... it saves typing.

The second argument in our example was: "hi Bob".    The "" were used to group these words into a single argument ... otherwise the wish program would have taken "hi" as the second argument and "Bob" as the third.   The puts command would only be expecting 2 arguments and our little program would not have worked very well.    This concept of grouping is in almost every computer language ... they don't always use "" as the group markers, however.    The series of words inside the "" are often referred to as a "string" ... which is short for "string of characters".
 

Summary


End of Lesson 1.


Copyright of iCanProgram Inc. 2002