120 likes | 349 Views
Tcl/Tk 1. CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 3, 2002. Outline. Install Tcl/Tk Run some demos Create some simple widgets. Install Tcl/Tk. Follow the instructions on the handout to copy and install Tcl/Tk Run some demo programs:
E N D
Tcl/Tk 1 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 3, 2002
Outline • Install Tcl/Tk • Run some demos • Create some simple widgets
Install Tcl/Tk • Follow the instructions on the handout to copy and install Tcl/Tk • Run some demo programs: Start/Programs/ActiveState ActiveTcl 8.4.1.0/ Demos/Tk • Check out the documentation ActiveTcl8.4.1.0-html/index.html Right click on Package Documentation to Open in New Window
start.tcl • Follow the instructions on the handout to copy start.tcl • Double-click start.tcl • Close start.tcl • Open start.tcl with WordPad (or Notepad)
Variables in Tcl Use set for assignment set foo 123 set tw .top Use $ for reference set bar $foo toplevel $tw
Widgets in Tk . Widget names follow a hierarchy top .top.2.b4 2 b1 b2 b3 b4
frame and pack Use frame to create a logical group of widgets Use pack to display a widget frame $tw.2 pack $tw.2
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"
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
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
proc proc foo {bar} { global baz set baz $bar } proc Digit {arg} { DisplayMe $arg } The global variablebaz needs to bedeclared inside foo
Finishing the lab • Add more buttons • Add a label widget for a display • Change DisplayMe to update the label you just created