Download presentation
Presentation is loading. Please wait.
1
Tcl/Tk 1 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 3, 2002
2
2 Outline Install Tcl/Tk Run some demos Create some simple widgets
3
3 Install Tcl/Tk 1.Follow the instructions on the handout to copy and install Tcl/Tk 2.Run some demo programs: Start/Programs/ActiveState ActiveTcl 8.4.1.0/ Demos/Tk 3.Check out the documentation ActiveTcl8.4.1.0-html/index.html Right click on Package Documentation to Open in New Window
4
4 start.tcl 1.Follow the instructions on the handout to copy start.tcl 2.Double-click start.tcl 3.Close start.tcl 4.Open start.tcl with WordPad (or Notepad)
5
5 Variables in Tcl Use set for assignment set foo 123 set tw.top Use $ for reference set bar $foo toplevel $tw
6
6 Widgets in Tk Widget names follow a hierarchy. top 2 b1b2b3b4.top.2.b4
7
7 frame and pack Use frame to create a logical group of widgets Use pack to display a widget frame $tw.2 pack $tw.2
8
8 button The button command creates a button button $tw.2.b1 Attributes may be specified when creating the widget or later with configure : button $tw.2.b1 -text "7" -command "Digit 7" or $tw.2.b1 configure -text "7" -command "Digit 7"
9
9 foreach foreach takes 3 arguments: a loop variable a list of items to assign to the loop variable a block of code The block of code is executed once for each item in the list
10
10 foreach example foreach col {1 2 3 4} { pack $tw.$row.b$col } is the same as: pack $tw.$row.b1 pack $tw.$row.b2 pack $tw.$row.b3 pack $tw.$row.b4
11
11 proc proc foo {bar} { global baz set baz $bar } proc Digit {arg} { DisplayMe $arg } The global variable baz needs to be declared inside foo
12
12 Finishing the lab 1.Add more buttons 2.Add a label widget for a display 3.Change DisplayMe to update the label you just created
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.