Tcl/Tk 2 - PowerPoint PPT Presentation

About This Presentation
Title:

Tcl/Tk 2

Description:

TclTk 2 – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 14
Provided by: markaardis
Category:
Tags: tcl | widget

less

Transcript and Presenter's Notes

Title: Tcl/Tk 2


1
Tcl/Tk 2
  • CS 414, Software Engineering I
  • Mark Ardis
  • Rose-Hulman Institute
  • December 5, 2002

2
Outline
  • Tcl syntax
  • Menus
  • Key bindings
  • Expression evaluation
  • Control structures

3
Tcl Syntax 1/3
  • Every Tcl statement begins with a command
  • ltcommandgt ltargumentsgt
  • set foo bar
  • button tw.2.b1 -text "7" ...
  • foreach col 1 2 3 4 ...

4
Tcl Syntax 2/3
  • Whitespace (spaces or tabs) separates a command
    from its arguments (and arguments from one
    another)
  • Newline or semicolon ends a command
  • Use \ to continue a command on another line

5
Tcl Syntax 3/3
  • Double quotes and curly braces are used to group
    words together into one argument
  • Quotes allow substitutions to occur
  • Curly braces do not allow substitutions

6
Menus
  • Use menu to create a menu
  • menu tw.menu -tearoff 0
  • Use configure -menu to attach a menu to ltwidgetgt
  • tw configure -menu tw.menu

7
More Menus
  • Use add command to add an entry to a menu
  • m add command -label "Quit"
    -command Quit

8
Binding keys
  • The bind command takes 3 arguments
  • a widget (where the binding has effect)
  • a key sequence
  • a command
  • bind tw ltControl-Key-qgt "Quit"

9
Expression Evaluation
  • Expressions are evaluated by invoking the expr
    command
  • set len expr foo 3
  • Note that square brackets enclose commands

10
Control Structures
  • foreach (saw earlier)
  • if
  • switch
  • exit

11
if
  • if condition
  • statements
  • else
  • statements

if x 0 puts stderr "Divide by zero"
else set slope expr y / x
12
switch
  • switch ltvaluegt
  • lttag1gt statements
  • lttag2gt statements
  • ...
  • default statements
  • switch foo
  • bar set x 0
  • baz set x 1

13
exit
  • exit terminates the application
Write a Comment
User Comments (0)
About PowerShow.com