1 / 13

Tcl and Tk

Tcl and Tk. CSE 470 Fall 1999 Revised by Prasad. Objective . To use Tcl Tk to develop GUI and prototype of the project. What is Tcl/Tk ? . Tcl (Tools Command Lanuage): is a simple string based scripting language for controlling and extending applications.

mabli
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 CSE 470 Fall 1999 Revised by Prasad

  2. Objective • To use Tcl Tk to develop GUI and prototype of the project

  3. What is Tcl/Tk ? • Tcl (Tools Command Lanuage): is a simple string based scripting language for controlling and extending applications. • Tcl provides generic programming facilities such as variables, loops, and procedures. • Tk: a Tool kit based on X-window system. • Tk provides facilities (widgets) for building user interfaces. • Tcl/Tk are excellent tools for Rapid prototyping.

  4. Tcl/Tk .. continued • Tcl/Tk is interpreted rather than compiled ( The interpreter is in !/opt/bin/wish ) • It is a weakly typed language (strings and integer variables are interchangeable). • Tcl syntax is very much similar to UNIX shell programming.

  5. Tcl primitives • Assignment Value set name “ “ set ID 89 89 set number ID ID set number $ID 89 • if statement: if {$turn == “0”} { computer_move } else { player_move }

  6. Tcl Primitives • Procedures, expressions … proc diag {a b} { set c [expr sqrt($a * $a + $b * $b) ] return $c } • Loops (the while loop) while {$i <= 10} { set I [expr $i+1] }

  7. Tk Fundamentals • Tk provides commands for creating and manipulating widgets. • Widgets types include buttons, scroll bars, text boxes, scales, canvas etc. • The three step procedure for creating a widget. 1) Declare the widget 2) Define any event procedure 3) Pack the Widget.

  8. A simple example: Push Button • Declaring the widget button .pushbutton -text pushme -command procpush • Defining Event Procedure proc procpush {} { .pushbutton config -text “I am pushed” } • Packing pack .pushbutton -side top • Execute the script wish filename.tk

  9. Simple Example: contd ...

  10. Naming conventions • Widgets should be referred in a hierarchical fashion. • Names of all top level widgets start with a “. “ (period). • Example: Say we have top level entity as frame and inside it we have a button. frame .entryframe button .entryframe.pushbutton -text “push me” • Thus all widgets have a parent-child relationship.

  11. Timer • The after command: • after 1000 Makes the program wait for 1000ms before proceeding further. • after 1000 proc Fires the procedure proc after 1000ms but proceeds immediately to the next statement after after statement.

  12. Example 2

  13. Examples of widgets • Canvas canvas .colorwin -width 7c -height 2c • Scale scale .redscale -label Red -from 0 -to 255 -length 7c • Frame frame .entryframe • Text Box entry .entryframe.Namebox -width 7 -height 2

More Related