1 / 10

TCL TK

TCL TK. 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. Tcl history.

sbraun
Télécharger la présentation

TCL TK

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. 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 Tcl/Tk features

  5. Using Tcl/Tk • Three modes: • tclsh for interactive use $tclsh %set x 7 7 • 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 }

More Related