TclTk 1 - PowerPoint PPT Presentation

About This Presentation
Title:

TclTk 1

Description:

Attributes may be specified when creating the widget. or later with configure : ... Add a label widget for a display. Change DisplayMe to update the label you ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 13
Provided by: markaardis
Category:
Tags: tcltk | widget

less

Transcript and Presenter's Notes

Title: TclTk 1


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.bcol
  • 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
Write a Comment
User Comments (0)
About PowerShow.com