Presentation is loading. Please wait.

Presentation is loading. Please wait.

TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,

Similar presentations


Presentation on theme: "TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,"— Presentation transcript:

1 TCL TK

2 Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS, MacOS X –also found in Python and Perl GUI extensions –scripts can send commands to each other

3 Tcl history Developed in late 1980s by John Ousterhout first release ~1991 Tk usable around 1992 see http://www.tcl.tk/doc/tclHistory.html

4 Tcl/Tk features high-level scripting language –less code than Win32 interpreted –execute directly, without compiling or linking extensible –commands in Tcl or C embeddable –Tcl interpreter callable from C most platforms –Unix, Mac, Windows –hides UI, system call differences autoloading –automatically load libraries free –source –no royalties

5 Using Tcl/Tk Three modes: 1.tclsh for interactive use $ tclsh % set x 7 7 2.wish for window programs $ wish % button.b –text “Hello” –command exit % pack.b

6 Tcl/Tk script files Script file: #!/usr/local/gnu/bin/wish –f button.b –text "Hello, world!" \ –command exit pack.b

7 Basic operations print to screen ( puts ) puts –nonewline "Hello, world!" puts "!!" assignment ( set ) set income 32000 puts "income is $income" (using '$' to get the value of a variable) mathematical expressions ( expr ) set a 10.0 expr $a + 5 expr int($a/3)

8 Some useful commands unset : destroy a variable unset num info : check whether the named variable has been defined if {![info exists num]} { set num 0 } incr num window commands wm withdraw. console show

9 Special characters # : single-line comments, similar to "//" in C \ : escape character, same function as in C : also used to break a long line of code to two lines $ : get the value of a variable –var : name of variable –$var : value of variable [] : evaluate command inside brackets

10 Control structures if then else set income 32000 if {$income > 30000} { puts "$income -- high" } elseif {$income > 20000} { puts "$income -- middle" } else { puts "$income -- low" } while loops set i 0 while {$i < 100} { puts "I am at count $i" incr i }


Download ppt "TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,"

Similar presentations


Ads by Google