1 / 25

Tcl and Tk

Tcl and Tk. Chen Wei, Gingko Studio. Content. history and purpose Important Features Tcl Syntax Tk Examples. Content. history and purpose Important Features Tcl Syntax Tk Examples. How it started. Codes must be modified when the environment is changed, so a lot of time is wasted.

ardith
Download Presentation

Tcl and 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 and Tk Chen Wei, Gingko Studio

  2. Content • history and purpose • Important Features • Tcl Syntax • Tk Examples

  3. Content • history and purpose • Important Features • Tcl Syntax • Tk Examples

  4. How it started Codes must be modified when the environment is changed, so a lot of time is wasted. Find a programming language which can be: 1. Reused 2. Extended 3. Learned quickly Solution: Component Approach

  5. What is Tcl? • developed by John Ousterhout (OH-stir-howt) at UC Berkeley. • Tcl stands for “tool command language” • interpreted scripting language; • most commonly used to build graphical interfaces in conjunction with Tk.

  6. Cont… What is Tcl? • The Tcl interpreter has been ported from UNIX to DOS, Windows, OS/2, NT, and Macintosh environments. • The Tk toolkit has been ported from X Window to Windows and Macintosh.

  7. What is Tk? • A graphical toolkit that gives one access to many of the graphics primitives of the underlying windowing system, as well as providing access to many types of widgets, such as buttons, scrollbars, menus, and text boxes. • a set of commands and procedures that make it relatively easy to program graphical user interfaces in Tcl. • Tk defines Tcl commands that let you create and manipulate user interfaces.

  8. What is tclsh and wish? tclsh is an interpreter which interprets tcl commands • wish is an interpreter that one can use that: • Interprets tcl commands • Interprets tk commands

  9. Content • history and purpose • Important Features • Tcl Syntax • Tk Examples

  10. Features • Easy to learn • Standard systax • Graphical interfaces • Cross-platform applications • Rapid development • Extensive and embeddable • Flexible integration • Free

  11. Content • history and purpose • Important Features • Tcl Syntax • Tk Examples

  12. Basics • Tcl script = • Sequence of commands. • Commands separated by newlines, semicolons. • Tcl command = • One or more words separated by white space. • First word is command name, others are arguments. • Returns string result. • Examples: set a 22 puts "Hello, World!"

  13. Tcl: Tool Command Language • Simple syntax (similar to sh): • set a 47í47 • Substitutions: • set b $aí47 • set b [expr $a+10]í57 • Quoting: • set b "a is $a"ía is 47 • set b {[expr $a+10]}í[expr $a+10]

  14. More On The Tcl Language • Rich set of built-in commands: • Variables, associative arrays, lists. • C-like expressions. • Conditionals, looping: if "$x < 3" { puts "x is too small" } • Procedures. • Access to files, subprocesses, network sockets

  15. More On The Tcl Language • Only data representation is zero-terminated strings: • Easy access from C. • Programs and data interchangeable. set cmd1 "exec notepad" ... eval $cmd1 (notepad.exe launches under Windows)

  16. Example: Factorial proc fac x { if {$x<=1} { return 1 } expr {$x*[fac [expr $x-1]]} } fac 4 Returns: 24

  17. Content • history and purpose • Important Features • Tcl Syntax • Tk Examples

  18. Hello World pack [button .b -text "Hello" -command {puts "Hello World!"}] • This shows a Hello button on the Main window. • When you click the button the console window will display the string "Hello World!" on the console. • button command creates an instance .b button called .hello. • -text string shows the button title. • -command string is the command responded to the button's action. • pack command layouts the button on the window.

  19. Browser Wish Script scrollbar .h -orient horizontal -command ".list xview" scrollbar .v -command ".list yview" listbox .list -selectmode single -width 20 -height 10 \ -setgrid 1 -xscroll ".h set" -yscroll ".v set" label .label -text "File Selected:" -justify left entry .e -textvariable fileSelected

  20. Cont… Browser Wish Script • grid .list -row 0 -column 0 -columnspan 2 -sticky "news" • grid .v -row 0 -column 2 -sticky "ns" • grid .h -row 1 -column 0 -columnspan 2 -sticky "we" • grid .label -row 2 -column 0 • grid .e -row 3 -column 0 -columnspan 3 -sticky "we" • grid columnconfigure . 0 -weight 1 • grid rowconfigure . 0 -weight 1

  21. Cont… Browser Wish Script foreach file [glob *] { .list insert end $file } bind .list <ButtonRelease-1> \ {global fileSelected;set fileSelected \ [%W get [%W curselection]]}

  22. The End

More Related