IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

The Linux Tcl and Tk HOWTO

Search Howtos :Match :
Next Previous Contents

5. Just a little bit of Programming

Since Tcl is an interpreted language, to run a Tcl program (also called a script), you normally pass the script file to the Tcl interpreter, wish, for example:


wish hello.tcl

You can also use wish in interactive mode and type in commands at the command line.

There's another standard Tcl interpreter, tclsh, which only understands the Tcl language. Tclsh does not have any of the Tk user interface commands, so you cannot create graphical programs in tclsh.

Some Tcl freeware applications extend the Tcl language by adding new commands written as C functions. If such is the case, you need to compile the applicati on instead of just passing its Tcl code to the wish interpreter. This application program, from a Tcl perspective, is really a new version of the wish interpret er, which the new C commands linked in. Of course, the application program may be a lot more than merely a Tcl interpreter. (Note: you can also use Tcl's auto-loading capability on systems that support it.)

5.1 The one-minute program in Tcl

Tcl has a simple structure. Each line starts out with a command, such as button and a number of arguments. Each command is implemented as if it was a C function. This function is responsible for handling all the arguments.

As a very standard example, the following is the Hello World program in Tcl/Tk:


# This is a comment
button .b -text "Hello World" -command exit
pack .b

In this case you have to type the commands interactively to tclsh or wish.

You can also place command into script files and invoke these just like shell scripts. To do this for the previous example, rewrite the Hello World program as follows:


#! /usr/local/bin wish -f
button .b -text "Hello World" -command exit
pack .b

Put the text inside a file called Hello and make sure that wish is installed in /usr/local/bin (otherwise you will have to change opportunely the path).

Make the file Hello executable issuing the command


chmod 775 Hello

and run it inside X.

You will see a button labelled Hello World inside a window: clicking it will close (exit) the window.


Next Previous Contents
Search Howtos :Match :
Python 3.0
Interpreted, interactive, object-oriented programming language
VLC media player 0.9.8a
Cross-platform media player and streaming server
Transmission 1.41 beta 2
Lightweight, yet powerful BitTorrent client
X-Moto 0.5.0
2D motocross platform game
Gdm 2.25.1
Reimplementation of the well known xdm program.
Linux Kernel 2.6 2.6.28-rc7
Linux Kernel
Linux Kernel 2.4 2.4.37
Linux Kernel
SquirrelMail 1.4.17
PHP Based Webmail Product
GNOME 2.25.2
GNOME desktop environment
WebGUI 7.6.5
A fully featured content management system.
Free IT Magazines, White Papers, eBooks, and more !
Dr. Dobb's Journal

Dr. Dobb's Journal enables programmers to write the most efficient and sophisticated programs and help in daily programming quandaries.

The 7 Things that IT Security Professionals MUST KNOW!

Gain key insight into security problem and find the safest means to protect your technological assets.

Database Trends and Applications

Provides timely coverage of the technology, intelligence and insight needed to plan, implement and manage information-rich projects.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info