Tcl/Tk Quick Start

2y ago
21 Views
3 Downloads
482.91 KB
30 Pages
Last View : 7d ago
Last Download : 3m ago
Upload by : Bria Koontz
Transcription

Tcl/Tk quick startPresented by developerWorks, your source for great tutorialsibm.com/developerWorksTable of ContentsIf you're viewing this document online, you can click any of the topics below to link directly to that section.1. About this tutorial.22. Tcl/Tk basics .33. The Tcl language.44. Tk commands .175. Getting to know Expect.226. Tcl/Tk extensions.267. Resources and feedback .29Tcl/Tk quick startPage 1 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksSection 1. About this tutorialWho should take this tutorial?This tutorial is designed for those with experiencein one or more programming or scriptinglanguages. While Tcl/Tk is available on severalplatforms, including Win32 and MacOS as well asseveral of the *NIX environments, this tutorial iswritten in the context of running on a GNU/Linuxinstallation.Starting out, I'll introduce Tcl/Tk and summarize asmall part of the language's history. Then, I'llreview key features of the Tcl/Tk scriptinglanguage and interpreter, discuss some of theextensions to the language, and examine severalexamples of Tcl/Tk in action. The text isaccompanied by code fragments and occasionallyan image of the resulting output (since Tk is a GUItoolkit, after all).Finally, I'll wrap up with a presentation of someexternal resources, both Web and print, to help youdeeper into the Tcl/Tk environment.About the authorBrian Bilbrey is a system administrator, productengineer, webmaster, and author. Linux is a tool inhis daily work as well as his avocation, much to thechagrin of his long-suffering spouse, Marcia.He welcomes your feedback on this tutorial orother related Linux topics atbilbrey@orbdesigns.com. His daily journal on lifewith Linux and other adventures can be found atOrbDesigns.com.Tcl/Tk quick startPage 2 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksSection 2. Tcl/Tk basicsOrigins of Tcl/TkTcl stands for Tool Control Language. Tk is theGraphical Toolkit extension of Tcl, providing avariety of standard GUI interface items to facilitaterapid, high-level application development.Development on Tcl/Tk, pronounced "tickletee-kay", began in 1988 by John K. Ousterhout(shown in the image), then a Professor at U.C.Berkeley (UCB). Tcl was designed with the specificgoals of extensibility, a shallow learning curve, andease of embedding. Tk development began in1989, and the first version was available in 1991.Dr. Ousterhout continued development of Tcl/Tkafter he left UCB, then going to work for SunMicrosystems for a stint. Now at Scriptics (whichbegat Ajuba Solutions, which was purchased byInterwoven), he keeps on improving the language,currently in version 8.3.2 stable and 8.4development, as of this writing.See the "History of Tcl" page for more details.Tools and filesThere are two main programs that you need on your Linux system to explore Tcl/Tk. Theseare tclsh and wish. As you might discern from its name, the former is a Tcl shell, mostfrequently used to provide execution context for a shell script. Wish is the equivalent, for awindowed GUI environment.Check for the presence of these files by typing the following: /tcltk which tclsh/usr/bin/tclsh /tcltk which wish/usr/bin/wishThe which command returns the path to the specified executable. If you don't see resultssimilar to these, then you'll want to head over to the Scriptics Tcl/Tk page to download andbuild your own copy. Of course, the absence of these programs on your system is notindicative of any problem. Unlike Perl, Tcl/Tk is generally not regarded as essential to theoperation of Linux. Every distribution I'm aware of ships with a version of Tcl/Tk and the mostpopular extensions as a part of the CDROM or online repository collection. From thesesources, the tools are generally fairly easy to install. If you have difficulty, contact thepublisher of your GNU/Linux software.Tcl/Tk quick startPage 3 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksSection 3. The Tcl languageWhat makes Tcl tick?In the following listing, you'll find a common firstexample program, as implemented in Tcl. This is acomplete script: the first line invokes the tclshenvironment, and the second does the actual work.Create the script with a text editor of yourchoosing, make it executable by typing chmod xhello.tcl, then execute it to test yourhandiwork. /tcltk cat hello.tcl#!/usr/bin/tclshputs stdout {Hello, World!} /tcltk ./hello.tclHello, World!Tcl and Tk are interpreted, extensible scriptinglanguages. The license, which is very similar to theBSD license, permits free use under anycircumstances, as long as the copyright is retainedin all copies and notices pass verbatim in anydistribution. The license terms make Tcl/Tk freesoftware.Tcl/Tk is an interpreted environment. The Tclinterpreter can be extended by addingpre-compiled C functions, which can be called fromwithin the Tcl environment. These extensions canbe custom for a specific purpose, or generic andwidely useful. We'll look at a number of extensionslater in the tutorial, with special attention given tothe first extension, the very popular Expect.In next few panels, we'll review the major featuresof the Tcl language, from metacharacters andglobal variables, to operators, mathematicalfunctions, and core commands. After all, theTcl/Tk quick startPage 4 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorkscommands make Tcl/Tk the distinctive evolvinglanguage it is. Bear in mind that we do not havethe space in this tutorial to cover every command.The highlights are here, the depths are yours toexplore at a later date.#!/usr/bin/tclsh# filename hello2.tcl# This program code showsMetacharacters are those characters or character# metacharacter usagepairs that have special meaning in the context ofputs stdout "Hello, World! \a"puts stdout {Hello, World! \a}the Tcl/Tk environment, including groupingset Pints 6statements, encapsulating strings, terminatingset Days 7statementsand more, as delineated in theputs stdout "The answer to the\following table. Many of these are demonstrated inuniverse is [eval Pints * Days]!\n"***the code listing to the left. One special feature to /tcltk ./hello2.tclnotice is the difference in output when curly bracesHello, World!(which prevent substitution and expansion) areHello, World! \aused in place of double quotes.The answer to everything is 42!Tcl metacharactersCharacter(s)#; or tring]\char\Used asCommentStatement separatorsA variable (case sensitive)Array VariableMultidimensional ArrayQuoting with substitutionQuoting without substitutionCommand substitutionBackslash substitutionLine continuation (at end of line)#!/usr/bin/tclsh## Demonstrate global variables# and backslash substitutionif { argc 1} {Several global variables exist (and are pre-defined,set N 1if not null in the current context) when a Tcl/Tkforeach Arg argv {puts stdout " N: Arg\n"script begins running. These variables permitset N [expr N 1] access to the operating environment as follows:if { Arg "ring"} {argc is the count of arguments to the script, notputs stdout "\a"counting the name as invoked. argv is a list (not an}array) of arguments. argv0 is the invoked filename}} else {(which may be a symlink). env is an array that isputs stdout " argv0 on \ indexed by the names of the current shell'sX Display env(DISPLAY)\n"environment variables. errorCode stores}information about the most recent Tcl error, while***errorInfo contains a stack trace from the same /tcltk ./hello3.tclTcl global variables andbackslash substitutionsTcl/Tk quick startPage 5 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorks./hello3.tcl on X Display :0.0event. The list goes on with another dozen tcl xxx /tcltk ./hello3.tcl ring variables from tcl interactive to1: ringtcl version. A good summary is found in Tcl/Tkin a Nutshell (see the Resources at the end of thistutorial for more information).Several of these variables are used in the samplecode at left, along with (once again) somebackslash-quoted characters, \n and \a. \charallows substitution of non-printing ASCIIcharacters. This is common to many scripting andshell environments under UNIX. As noted in thetable, a backslash-quoted character that has nodefined substitution is simply echoed to output.\character\a\b\f\n or \newline\r\t\v\space ("\ ewlineCarriage returnHorizontal tabVertical TabSpaceOctal valueHexadecimal valueEcho 'c'Backslash /tcltk cat maths.tcl#!/usr/bin/tclsh## Demonstrate operators and# math functionsset PI [expr 2 * asin(1.0)] Tcl supports a standard array of operators andmathematical functions. The operators includeif { argc 3} {set X [lindex argv 0]arithmetic, bitwise, and logical operators, which areset Y [lindex argv 1]evaluated via the expr command using commonset Rad [lindex argv 2] operator precedence rules. Also, considering Tcl'sset Dist [expr sqrt(( X* X) ( Y* Y))]set Cir [expr 2* PI* Rad] fundamental roots as a string-oriented scriptinglanguage, there's a reasonable complement ofset Area [expr PI* Rad* Rad]puts stdout "Distance Dist"mathematical functions as follows:puts stdout "Circumference Cir"puts stdout "Area Area"* Trigonometric functions include cos(x),} else {acos(x), cosh(x), sin(x), asin(x), sinh(x),puts stdout "Wrong argument count!"puts stdout "Needs X, Y, and Radius"tan(x), atan(x), atan2(y, x), tanh(x), and}hypot(x, y). The pertinent unit for these********functions is radians. /tcltk ./maths.tcl 3 4 5*TheLog functions are exp(x), log(x), andDistance 5.0log10(x).Circumference 31.4159265359Tcl operators andmathematical functionsTcl/Tk quick startPage 6 of 30

Presented by developerWorks, your source for great tutorialsArea 78.5398163397ibm.com/developerWorks* The Arithmetic functions are ceil(x), floor(x),fmod(x, y), pow(x, y), abs(x), int(x), double(x),and round(x).* Random numbers are handled by rand() andsrand(x).The example at left makes use of just a few ofthese operators and functions to calculate thedistance between a specified point and the origin,and to return the circumference and area of a circleof the specified radius. Additionally, in this examplewe use the list index (lindex) command to accessindividual elements of argv.## parse command line switchesThe looping commands in Tcl are while, for, andset Optimize 0foreach. The conditional (branching) commandsset Verbose 0foreach Arg argv {are if/then/else/elsif and switch. Modifiers for theswitch -glob -- Arg preceding{commands are break, continue, return,-o* {set Optimize 1}anderror.Finally,the catch command is provided-v* {set Verbose 1}forerrorhandling.default {error "Unknown Arg"}if/then/else/elsif was demonstrated in previous}panels. While then is a part of the formal syntax, it}is most often observed in absentia.set LineCount 0while {[gets stdin Line] 0} {# to confuse Vanna White.In the example at the left, a switch command is fedRemove Vowels Line \the command line arguments by the foreach Optimize Verboseincr LineCount}return LineCount.Looping and branching in TclTcl/Tk quick startPage 7 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksconstruct. As the arguments are processed (Note:improper input terminates the script, since wehaven't implemented an error catch), the while loopprocesses input by calling a procedure for eachline, and incrementing a line counter. The codefragment ends by returning the count of linesprocessed. /tcltk tclsh% set Phrase "hello, world!"hello, world!% string toupper PhraseHELLO, WORLD!Strings are the fundamental data type in Tcl. The% string totitle Phrasestring command is really a variety of commands,Hello, world!% string match ello Phrase gathered under one umbrella. In use, string reads0much like the application of specific object% string match *ello* Phrasemethods from OOP programming, as you can see1in the example on the left.% string length Phrase14% append Phrase "Nice day, eh?"The informational string commands are length andhello, world!bytelength (which can differ, depending onNice day, eh?character set). Comparisons that return boolean% string toupper Phrasevalues (1 or 0) are compare, equal, and match.HELLO, WORLD!NICE DAY, EH?Pattern matching here is accomplished by% string wordend Phrase 7 "globbing", the simple type of matching commonly12associated with shell operations. AdvancedTcl strings and patternmatchingRegular Expressions are also available via thedistinct regex and regsub commands.Indexing functions in Tcl are performed with theindex, last, first, wordend, and wordstartcommands. String modification is handled byTcl/Tk quick startPage 8 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorkstolower, toupper, totitle, trim, trimleft, trimright,replace, and map. The latter requires a charactermapping table to be pre-defined. Substrings areextracted with range, and strings are outputmultiple times with repeat.Text can be added to an existing variable using theappend command. The format command can beused to generate output strings using the samestyles and conventions as the C language's printfcommand. scan parses a string and assigns valuesto variables. Finally, starting with Tcl 8.0,functionality for handling binary data as strings(thus able to process the null character withoutfailure) was added, with the binary format andbinary scan commands. /tcltk tclsh% set c1 {Bob Carol}Bob CarolLists have two major uses in Tcl. The first we've% set c2 [list Ted Alice]already seen demonstrated in the context ofTed Alice% set Party1 [list c1 c2] processing command line arguments via the{Bob Carol} {Ted Alice}foreach command (found on Looping and% set Party2 [concat c1 c2]branching in Tcl on page 7 ). The second use is toBob Carol Ted Alice% linsert Party1 1 Richard build up elements of a Tcl command dynamically,{Bob Carol} Richard {Ted Alice}which can be later executed by using the eval%command, as we see later in this tutorial.Tcl listsThe list command takes all of its arguments andreturns them in a list context. Arguments may bevalues or variables. From the example at left, listscan be created manually, or using list, which cantake other lists as arguments (thus saving the twocouples orientation of our first "Party").Alternatively, the concat command is used tomerge two or more lists into a single entity oftop-level items, returning the second, moreinteresting "Party".Tcl/Tk quick startPage 9 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksSome other useful list commands and their syntaxare:* llength List - returns count of toplevel items.* lindex List n - returns indexed item, countsfrom zero.* lrange List i j - returns range of listelements.* lappend List item. - append items to list.* linsert List n item. - inserts item(s) at thespecified position in the list, moving otheritems down the list.The balance of list commands include lreplace,lsearch, and lsort. The split command takes astring as input and generates a properly parsedlist, breaking the string at the specified character.join performs the complementary operation, takinglist elements and stringing them together,separated by a joinstring. /tcltk tclsh% set People(friend) TomTom% set People(spouse) Marcia The shortcut to understanding Tcl arrays is toregard them in the same light as you would a PerlMarcia% set People(boss) Jackhash. The array is not a numerically indexed linearJackdata structure, unless you choose to impose that% array names Peopleinterpretation upon your data. The index (or key)friend boss spouse% set Person People(friend) may be any string, although strings with spacesTomneed either to be quoted, or a variable reference.% array get Peoplefriend Tom boss Jack spouse MarciaJust as with normal variables, arrays are initialized% set People(friend) \with the set command, as shown at left. The index[concat People(friend) Bob]Tom Bob% set Person People(friend)Tom Bob%Tcl arraysTcl/Tk quick startPage 10 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksis given inside parentheses. Please note that theparentheses do not provide grouping like curlybrackets or double quotes. Once initialized as anarray, a variable may not be accessed as asingular variable. As shown at the bottom of thelisting to the left, array elements may also be lists.More Tcl arraysThe array command is a multi-purpose tool, much like string. The commands are array existsto test a variable for existence as an array, array get to convert to list format, array set toconvert from list to array, array names to return a list of indices, and array size to return thecount of indices. Searching through an array has its own set of four commands: arraystartseach, array anymore, array nextelement, and array donesearch.Although Tcl arrays are one-dimensional by design, there is an elegant way to simulatemulti-dimensional constructs. Since indices are arbitrary strings, a 2D array might bedeclared as follows:set i 1 ; set j 10set array( i, j) 3.14159incr jset array( i, j) 2.71828These array keys are really just the strings "1,10" and "1,11" respectively, but for thepurposes of accessing the data, who's to know the difference?#!/usr/bin/tclsh## Demonstrate procedures andThe proc command defines a Tcl procedure. Once# global scoping brieflyset PI [expr 2 * asin(1.0)]proc circum {rad} {global PIreturn [expr 2.0 * rad * PI]}proc c area {rad} {global PIreturn [expr rad * rad * PI]}set rad 3puts stdout "Area of circle of\radius rad is [c area rad],\n\the circumference is\[circum rad].\n"********* /tcltk ./protest.tclArea of circle of radius 3 is 28.2743338823,the circumference is 18.8495559215.Tcl proceduresTcl/Tk quick startPage 11 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksdefined, a procedure can be called or used just asa built-in Tcl command would be. Additionally,parameters can be defined with default values; forexample, changing the definition at the left to readproc c area { {rad 1} } would enable thec area procedure to be called without parameters,returning the area of the unit circle.The rename command is used just as it sounds, togive a new name to an existing command orprocedure. There are two distinct reasons for usingrename. The first is to add functionality to anexisting command by renaming the original, thenreplacing it with a procedure of the same name.The procedure can call the original, and addwhatever bells and whistles are necessary. Thesecond reason for rename is to map a commandout of existence, like rename exec {};, forexample, to prevent users from executing externalcommands.Variable scoping rulesRules of scope describe the visibility of procedure and variable names and values at differentlevels of the program. For instance, variables defined at the outermost level of a script areglobal variables. By default, these are not visible, nor are their values available from withinprocedures. This permits procedure writers to freely define variable names and assign valueswithout fear of overwriting important variables that are unknown at the local scope. To makea global variable visible inside a procedure, it must be declared as such within the procedure,as I did for PI (in the example on the previous panel) using the global command.The upvar command provides a facility for associating a local-level variable with the value ofa variable from another scope. This permits calling by name into procedures, which is handywhen the procedure needs to be able to modify the value at another scope, rather than justusing it. The command syntax is upvar level VarName LocalVar, where level is thenumber of steps up out of the current scope. "#0" is the representation of the global scopelevel.#!/usr/bin/tclsh## Demonstrate Data Structures# using procedural wrappers Beyond simple multi-dimensional arrays, it isgenerallyrecommendedthat Tcl data structures beproc UserAdd { Acct rName eMailphone} {global uDataimplemented as arrays that have dedicatedif {[info exists uData( Acct,rname)]}{procedural interfaces.This design hides specificreturn 1implementationdetailsfrom the user of the}structures, while providing the ability to performset uData( Acct,rname) rNameset uData( Acct,email) eMailsignificant error checking capabilities.set uData( Acct,phone) phonereturn 0In the example at left, after declaring uData as a}Data structures in TclTcl/Tk quick startPage 12 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksputs stdout [UserAdd bpb\global variable, the code executes a check to seeBrian bilbrey@junk.com 555-1212]that the account doesn't already exist. If it does,puts stdout [UserAdd tom\Tom tom@junk.com 555-1212] then the procedure returns with a (non-zero) errormessage. The return can be used in a switch toputs stdout [UserAdd bpb\Brian bilbrey@junk.com 555-1212]generate error text output. For the example, we******simply feed it three sequential inputs, including one /tcltk ./datas.tclrepeat. This yields the output shown at the bottom,0with the '1' indicating a purposeful error return due0to a repeating account name.1Other possibilities for data structures include listsof arrays, linked or doubly-linked arrays, or variouspermutations thereof. The lists of arrays constructare considerably more efficient with the listreimplementation that accompanied Tcl 8.0,providing constant access times. /tcltk tclsh% file exists hello3.tcl1File and path operations are a challenging problem% file executable testitin a cross-platform environment. Tcl uses UNIX0% file pathtype ./hello3.tcl pathnames (separated using the '/' character byrelativedefault), as well as the native pathname% set dir1 homeconstruction for the host OS. Even whenhomein-program data is constructed properly, it can be% set dir2 brianbriandifficult to ensure that user input matches the% set dir3 tcltksystem requirements. The file join command istcltkused to convert UNIX formats to native pathnames.% file join / dir1 dir2 dir3Other path string commands include file split,/home/dir2/dir3dirname, file extension, nativename, pathtype, and% file delete testit %tail.Paths and filesIn its role as a "Tool Control Language", Tcl has awide variety of internal file test and operationfeatures. Each command leads off with file, as inTcl/Tk quick startPage 13 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksfile exists name. Other test commands (which allreturn boolean values) include executable,isdirectory, isfile, owned, readable, and writable.File information and operations are accomplished(again, all with the leading file) atime, attributes,copy, delete, lstat, mkdir, mtime, readlink, rename,rootname, size, stat, and type. Note that a numberof the file information commands may returnundefined data when running in the Windows orMac environments, since, for example, inode andsymbolic (and hard) link data isn't represented inthose file systems.The advantage of using file . commands ratherthan using native commands via exec is that theformer presents a portable interface.This whole document could easily be devoted tojust this one section of the Tcl language. However,content yourself with the tclsh examples to the left,which reveal the flavor of these commands, andthen follow up with readings from the Resourceslisted at the end of the tutorial. /tcltk tclsh% nslookup orbdesigns.comServer:192.168.1.3The exec command is used to explicitly dress: 64.81.69.163% set d [date]Sun Mar 25 13:51:59 PST 2001% puts stdout d% set d [exec date]Sun Mar 25 13:52:19 PST 2001% puts stdout dSun Mar 25 13:52:19 PST 2001******% if [catch {open foo r} Chan] {puts stdout "Sorry, Dave.\n"}% gets ChanOne% gets ChanTwo% eof Chan0% close Chan%Processes and file I/O with TclTcl/Tk quick startPage 14 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksexternal commands. Under Linux, most externalcommands can be run directly when Tcl is ininteractive mode, as shown in the example at theleft. Running with exec returns the stdout output ofa program not to the screen, but to Tcl, whichallows the data to be assigned to a variable. Whena program is started in the background, theimmediate return value is the PID for the program.exec'd programs can take full advantage of I/Oredirection and pipelines in the UNIX environment.Other process commands are exit, whichterminates a running Tcl script, and pid, whichreturns the PID of current (or specified) process,handy for a variety of purposes. Tcl does notincorporate any native process control commands,but you can use the exec command in concert withPID data to accomplish many tasks.File manipulation uses the following commands:open, close, gets, puts, read, tell, seek, eof, andflush. As demonstrated at left, the catch commandis useful in error checking during file openingcommands. When the program output needs to beprinted before a newline character is encountered,as in a user data prompt, use flush to write theoutput buffer.An additional feature (in supported environments)is the ability to open pipelines in the same mannerthat you might a file. For instance, after opening apipeline channel with set Channel [open " sortfoobar" r], the output of the first gets is going to be"Eight" (alphabetically, out of file data "One"through "Ten", on 10 separate lines).Tcl/Tk quick startPage 15 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksUsing eval for dynamicscripting /tcltk cat input01.txt1 24 57 - 9 /tcltk tclshIn this% set InFile [open input01.txtr] example, you can sense the power of theeval command. Under normal circumstances, thefile3% while {[gets InFile Op] Tcl interpreter operates in a one-pass mode: It first 0} {parses the input command line (possibly stretchedset Operation "expr Op" over several physical lines), performing anyset Result [eval Operation]substitutions. Then execution takes place, unless aputs stdout " Op Result\n"bad or malformed command is found. eval permits}1 2 3a second pass (or perhaps more correctly, a4 5 9pre-pass). Thus a Tcl command can be first7 - 9 -2dynamically constructed, then parsed and%executed.In the listing at the left, the input file consists ofthree lines, each with one arithmetic operationshown per line. After invoking tclsh, the file isopened read only, and associated with the InFile variable. The while loop reads in oneline at a time, to Op. Then a complete Tclcommand is constructed by pre-pending expr tothe Op variable. This is then expanded,evaluated, and the result assigned accordingly.Finally, each operation and result is displayed onstdout.While this sample demonstrates a relatively trivialapplication of eval, conceptually it can be easilyextended to dynamic file and/or directoryprocessing based on the input of an input file ofknown syntax or to base operations on file type,permissions, access time or any variety of testableelements.Tcl/Tk quick startPage 16 of 30

Presented by developerWorks, your source for great tutorialsibm.com/developerWorksSection 4. Tk commandsWhat's a widget, anyway?Tk is the graphical Toolkit extension for Tcl. Tkrelease versions are coordinated with those of Tcl.In the panels that follow, we'll review the Tk widgetset, examine some of the configuration options,and set up some examples to demonstrate theuseful nature of Tk.It's difficult to convince any PHB (Pointy HairedBoss) that this section of the tutorial is workrelated. After all, it is about widgets, andconceptually widgets are closely related toplay.but this is work, so let's dig into it. First,here's the code for a Tk enhanced "Hello, World!"#!/usr/bin/wish## Hello World, Tk-stylebutton .hello -text Hello \-command {puts stdout \"Hello, World!"}button .goodbye -text Bye! \-command {exit}pack .hello -padx 60 -pady 5pack .goodbye -padx 60 -pady 5Invoking wish (the Tk shell) in the first line bringsup a Window widget of default size. Then I definedtwo button widgets, .hello and .goodbye -- theseare packed into the window, and the windowshrinks to the size defined by the specified buttonspacing. When the script is executed, you get thedialog shown at the left. Click on the button to get"Hello, World!" output in the parent terminalwindow, Click on to terminate the script.Tk widgetsThere are remarkably few commands used in the creation of Tk widgets. Better than half arevariants of button or text widgets, as you can see in the following list. Several of these itemsare demonstrated in the next panel.* button - a simple widget with over twenty configuration options from anchor and font topadx and relief.* canvas - canvas is a widget that can contain not only other widgets, but an assortmentof structured graphics, including circles, lines, and polygons.* checkbutton - creates a checkbox-style button widget, which is linked to a variable.* entry - builds a one-line text entry box.Tcl/Tk quick startPage 17 of 30

Presented by developerWorks, your source for great tutorials***********ibm.com/developerWorksframe - frame is a widget used primarily as either a container or spacer.label - creates a label object.list

Section 2. Tcl/Tk basics Origins of Tcl/Tk Tcl stands for Tool Control Language. Tk is the Graphical Toolkit extension of Tcl, providing a variety of standard GUI interface items to facilitate rapid, high-level application development. Development on Tcl/Tk, pronounced "tickle tee

Related Documents:

any Tcl built-in command. See Appendix A, “Basics of Tcl,” for information on Tcl syntax and on the extensions that have been added to the Tcl interpreter. Using Hierarchy Separators in Tcl Commands Many Tcl commands take an object name as an argument. The path

Tcl application. TclPro Wrapper makes it easy to distribute Tcl applications to your users and manage upgrades in Tcl versions. Tcl/Tk 8.2 The latest version of Tcl/Tk is pre-compiled and ready for use. Bundled extensions Several popular Tcl ext

Tcl interpreters from the C code and start feeding them Tcl commands to evaluate. It is also possible to de ne new Tcl commands that when evaluated by the Tcl interpreter call C functions de ned by the user. The tcltklibrary sets up the event loop and initializes a Tcl interpreter

Tcl lists, which share the syntax rules of Tcl com-mands, are explained in Chapter 5. Control structure like loops and if statements are described in Chapter 6. Chapter 7 describes Tcl procedures, which are new commands that you write in Tcl. Chapter 8 discusses Tcl arrays. Arrays are the mo

The TCL series is used for service purposes and for different industrial and laboratory tasks. For example, thermometers, temperature switches/thermostats, resistance thermometers and thermo-elements can be directly connected and checked. Versions: The TCL series of calibr

TCL / 16L 701 Kingshill Place, Carson, CA 90746 P: (310) 341-2037 nlslighting.com TCL LUMEN CHART PART NUMBER T2 LM/W BUG T3 LM/W BUG T4 LM/W BUG T5 LM/W BUG WATTS TCL-16L-175-30K 774 77 765 77 799 80 808 81 10 TCL-16L-175-40K 799 80 791 79 825 83 833 83 10

Tcl Fundamentals 1 This chapter describes the basic syntax rules for the Tcl scripting language. It describes the basic mechanisms used by the Tcl interpreter: substitution and grouping. It touches lightly on the following Tcl commands: puts ,

his greatest prestige and popularity with his novel Ariadne, in . identifies with Dorinda’s midlife awakening because she has been through that experience herself: after spending her life trying to live up to the standards of supportive wife, loving mother and perfect hostess that her husband’s elitist circle expected of her, “being my own person only became possible as an idea or a .