1 / 12

Tcl/Tk 1

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:

errin
Download Presentation

Tcl/Tk 1

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/Tk 1 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 3, 2002

  2. Outline • Install Tcl/Tk • Run some demos • Create some simple widgets

  3. 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

  4. 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)

  5. Variables in Tcl Use set for assignment set foo 123 set tw .top Use $ for reference set bar $foo toplevel $tw

  6. Widgets in Tk . Widget names follow a hierarchy top .top.2.b4 2 b1 b2 b3 b4

  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. 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. 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. 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. proc proc foo {bar} { global baz set baz $bar } proc Digit {arg} { DisplayMe $arg } The global variablebaz needs to bedeclared inside foo

  12. Finishing the lab • Add more buttons • Add a label widget for a display • Change DisplayMe to update the label you just created

More Related