Download presentation
Presentation is loading. Please wait.
1
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002
2
2 Outline Tcl syntax Menus Key bindings Expression evaluation Control structures
3
3 Tcl Syntax 1/3 Every Tcl statement begins with a command: set foo $bar button $tw.2.b1 -text "7"... foreach col {1 2 3 4}...
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
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
6 Menus Use menu to create a menu menu $tw.menu -tearoff 0 Use configure -menu to attach a menu to $tw configure -menu $tw.menu
7
7 More Menus Use add command to add an entry to a menu $m add command -label "Quit" -command Quit
8
8 Binding keys The bind command takes 3 arguments –a widget (where the binding has effect) –a key sequence –a command bind $tw "Quit"
9
9 Expression Evaluation Expressions are evaluated by invoking the expr command set len [expr $foo + 3] Note that square brackets enclose commands
10
10 Control Structures foreach (saw earlier) if switch exit
11
11 if if {condition} { statements } else { statements } if {$x == 0} { puts stderr "Divide by zero" } else { set slope [expr $y / $x] }
12
12 switch switch { { statements }... default { statements } } switch $foo { bar { set x 0 } baz { set x 1 } }
13
13 exit exit terminates the application
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.