Tcl%20/%20TK - PowerPoint PPT Presentation

About This Presentation
Title:

Tcl%20/%20TK

Description:

Tcl / TK 4322027 353-554 System Programming – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 29
Provided by: Ball171
Category:
Tags: 20tk | looping | structures | tcl

less

Transcript and Presenter's Notes

Title: Tcl%20/%20TK


1
Tcl / TK
  • ???????? ?????????????
  • 4322027

353-554 System Programming
2
Tcl / Tk
  • ????
  • Why used Tcl ?
  • Tcl Shell and Windowing Shell (Tclsh Wish)
  • Overview of main features of Tcl
  • Tk Fundamental
  • ???????????????????? Non-Interactive

3
????
  • ????????????????????????????????? UNIX
    ?????????????????????????????????????? Java,
    C/C, Python, Perl ??? Tcl ???????
  • Tcl/Tk ??????????? John K. Outsterhoot
    ??????????????????????????? ????????????????????
    ???????????? Interactive ????????
  • Tcl - Tool Command Language (??????? tickle)
    ????????????????????????????? Tcl shell (tclsh)
  • Tk - Toolkit (??????? tee-kay) ?????????????? GUI
    ?????? X window ?????????????? Windowing shell
    (wish)

EXIT
MAIN MENU
gt
lt
4
Why use Tcl ?
  • Easy to learn
  • Cross-platform support
  • Unix, Windows, Macintosh ??? ?????????????????? ?
    ???????????????????
  • Ready for enterprise
  • Flexible integration
  • Network-aware applications
  • Its free
  • Tcl Developer Xchange (http//dev.scriptics.com/so
    ftware/tcktk/downloadnow84.tml)

EXIT
MAIN MENU
gt
lt
5
Tcl Shell
  • Tclsh ???? shell ??? Tcl ???????????????????????
    ? ??? Tcl ??? Standard input ???? File
    ????????????????????????? ? ?????????????? Tclsh
    ?????????? Argument ???????????? Tcl ???
    Interactive ????????????? Argument ????????????
    Script ??????????????? non-Interactive
  • ?????????????????? Tclsh ??????????
    ??????????????????????? Tcl ??? ???????? Tclsh
    ????????????????? exit ???? ????????????

EXIT
MAIN MENU
gt
lt
6
Picture Tcl Shell
EXIT
MAIN MENU
gt
lt
7
Windowing Shell
  • Wish ????????????????????????????? Windowing
    Shell ??????????????????????? ? ??? Tcl,
    ???????????????? Tk ??? ??????????????????????????
    ????????????????? Standard input ????
    ?????????????
  • ????????????????? Graphic Application
    ????????????????????????????????????
  • ????????? Wish ????????? Interactive ???
    non-Interactive

EXIT
MAIN MENU
gt
lt
8
Picture Windowing Shell
EXIT
MAIN MENU
gt
lt
9
Overview of main features of Tcl
  • Basic syntax
  • Tcl ???????? Script ????????????? ?
    ????????????????????????????? ????
    ?????????????? ?????? ? ??????????????????????
    ????????????
  • ????????? Tcl ???????????? Word 1 ?? ???? ???????
    ?????????????????????????????????
    ??????????????????????????????????????????????????
    ? ????
  • expr 20 10 ???? expr 2010
  • ?????????????????????????????? String

EXIT
MAIN MENU
gt
lt
10
Overview of main features of Tcl
  • Variables
  • Tcl ??????????????????????????????????????????????
    ?????????????????????
  • ??????????????? set ??????????????????????????????
    ???????????? ????
  • set x 32 ??????????????? 32 ???????????? x
  • set x ??????????????????????? x
  • Tcl ??????????????????????????????????????????????
    ????? ????????????????????????????????????????????
    ?????????????????????
  • Tcl ???????????????????? ?????????????????????????
    ??? ? ???
  • ????????????????????????????
  • expr x3
  • ????????????????? ??????????????????????????????
    ???????????????????????

EXIT
MAIN MENU
gt
lt
11
Overview of main features of Tcl
  • Variable (???)
  • Variable substitution ??????????????? (Actual
    argument) ?????????????????
  • expr x3 gt expr 323
  • ????? Variable substitution ??????????????????????
    ??????????????????? ????
  • set cmd expr
  • set x 11
  • cmd xx
  • ??????????????????????????? cmd ?????????? expr
    ???
  • ????????????????? 3 ????????? expr xx

EXIT
MAIN MENU
gt
lt
12
Overview of main features of Tcl
  • Command substitution
  • ?????????????????????????????? ?????? Argument
    ????????????? ?
  • ???????????????????? ????????????? Tcl
    ?????????? ? ???????????????????? Nested Tcl
    command ??????? Tcl ??????????????????????????????
    Argument ???????????????? ????
  • set a 44
  • set b expr a4 --gt set b 176

EXIT
MAIN MENU
gt
lt
13
Overview of main features of Tcl
  • Quotes and Braces
  • Quotes ??????? Double Quotes ( )
  • ?????? Quotes ?????????????????????????????
    Argument ????? ??????????????????????????? ???
    ?????????????????????? ????
  • set x 24
  • set y 18
  • set z x y is expr x y
  • ????????????????? z ??????????? 24 18 is 42
  • ?????????????????????? ??????????????

EXIT
MAIN MENU
gt
lt
14
Overview of main features of Tcl
  • Quotes and Braces (???)
  • Braces ??????? Curly braces ( )
  • ?????? Curly braces ????????????????????????????
    Double-quotes ????????????????????????????????? ?
    ???????????? ???? ????
  • set z x y is expr x y
  • ????????????????? z ??????????? x y is expr
    x y

EXIT
MAIN MENU
gt
lt
15
Overview of main features of Tcl
  • Control structures
  • Procedures
  • Condition execution
  • Looping
  • ???????????????? Procedure ?????????????-?????????
    ???
  • proc time
  • set seconds clock seconds
  • put The time is clock format seconds

EXIT
MAIN MENU
gt
lt
16
Overview of main features of Tcl
  • Control structure (???)
  • ?????????????? Condition if ????????? Factorial
    ???????? Recursive
  • proc fac x
  • if x lt 0
  • error Invalid argument x must be a
    positive integer
  • elseif x lt 1
  • return 1
  • else
  • return expr x fac expr x - 1

EXIT
MAIN MENU
gt
lt
17
Overview of main features of Tcl
  • Control structure (???)
  • ???????????????????????????????? while
    ????????????????????
  • proc power base p
  • set result 1
  • while p gt 0
  • set result expr result base
  • set p expr p 1
  • return result

EXIT
MAIN MENU
gt
lt
18
Overview of main features of Tcl
  • Control structure (???)
  • ???????????????????????????????? for
    ????????????????????????? 0-9
  • for set x 0 xlt10 incr x
  • puts "x is x"
  • Where do commands come from
  • Built-in commands
  • Extension mechanism
  • Procedure

EXIT
MAIN MENU
gt
lt
19
Overview of main features of Tcl
  • Other features
  • ???????????????????????? String
  • ????????????????????????????????? I/O ???? Disk,
    Network sockets ???????
  • ????????????????????????????????
  • ??????????????????????????????????????????????????
    ???? exec
  • ???????????????????????????????????????
  • ???????????????????? Array
  • ?????? Script ????????????????????????????????????
    ???
  • ??????????????????????????????????????????????????
    ???
  • ???

EXIT
MAIN MENU
gt
lt
20
Tk Fundamentals
  • ????????????????????????????????????????? Tk ???
    Tk ???????? 35 ????????? Tcl
    ?????????????????????????? widget ?? Graphic User
    Interface ????????????? Tk ?????????????? X
    window, Windows ??? Macintosh ????????????????????
    ??????????????????? platforms ????????????????????
    ??????
  • Widget ??? ???????? (Window) ?????????????????????
    ????????? ????????????????????? ????? Widget ???
    Window ?????????????????? Widget ??????????????
    Buttons, Scrollbars, Menu ??? Text windows Tk
    ????? Canvas ???????????????????????????? ? ????
    Lines, Boxes ??? Bitmaps ???

EXIT
MAIN MENU
gt
lt
21
Tk Fundamentals
  • Widgets ?????????????????????????????????????????
    ? (Geometry manager) ?????????????????????????????
    ????????????? Tk ??????????? ??????????
    ????????????? widget ???? ? ???????
    ????????????????? Geometry manager ??? frame
    ???????? widget ?????????????????? widgets ???? ?
    ?????? widgets ???? ? ????????????????????????????
    ???? frame ????????? frame ????? frame
    ??????????????????????????????????????????????????
    ??????

EXIT
MAIN MENU
gt
lt
22
Tk Fundamentals
  • Tk widget-creation commands
  • button, canvas, checkbutton, entry, frame, label,
    listbox, menu, menubutton, message, radiobutton,
    scale, scrollbar, spinbox, text ??? toplevel
  • Tk widget-manipulation commands
  • bell, bind, bindtages, clipboard, destroy, event,
    focus, font, grab, grid, image, lower, option,
    pack, place, raise, selection, send, tk, tkerror,
    tkwaite, update, winfo ??? wm

EXIT
MAIN MENU
gt
lt
23
Tk Fundamentals
  • Hello, World!
  • button .b -text Hello command put stdout
    Hello, World!
  • pack .b padx 20 pady 10
  • .b configure background Green font "CordiaUPC
    30 bold italic underline"
  • ??????????????????????????????????????????????????
    ????? .b ??????????? ?????????? Hello
    ???????????????????????????????????????????????
    ??????? ????? Hello, World! ??? standard
    output ?????????????????????????????
    ????????????? pack ??????????????????????????
    ??????????????????????????????????????????
    ??????????????????????????????????????????????????
    ??????????????? ??????????????????? 00ff00
    (RRGGBB) ?????????????????????? CordiaUPC ????
    30 ?????????????????? ????? ?????????????

EXIT
MAIN MENU
gt
lt
24
Tk Fundamentals
  • ??????????????????????????????????????????????????
    ?????? ?????????????????????????????????? Hello,
    World! ??????????????????????????
  • .b configure -command tk_messageBox -message
    "Hello, World!" \
  • gt-type ok -title "Hello"
  • ???????????????????????????????? \
    ??????????????????????????????????????????????????
    ?????????????????????????

EXIT
MAIN MENU
gt
lt
25
Tk Fundamentals
  • Widget ???????????????? cget ????????????????????
    ?????????????????? ???????????????????????????????
    ??????????????????????????
  • .b cget background
  • gt Green
  • ???????????????????????????? Widget
    ?????????????????????????? configure
    ?????????????????? ? ???
  • .b configure background
  • gt -background background Background
    SystemButtonFace Green
  • (Command-line switch, Resource name, Class name,
    Default value, Current value )

EXIT
MAIN MENU
gt
lt
26
Tcl Script Power
!/usr/local/bin/tcl8.0/unix/tclsh set base
lindex argv 0 set p lindex argv 1 set
result 1 puts "Program argv0 puts "Base
base puts "Power p while p gt 0 set
result expr resultbase set p expr
p-1 puts stdout "Result is result"
EXIT
MAIN MENU
gt
lt
27
Tk Script Power
This script for Wish compute power
basep proc power base p set result 1 while
p gt 0 set result expr result
base set p expr p - 1 return
result .
EXIT
MAIN MENU
gt
lt
28
??????????
  • ??? ????????????. Tcl/Tk Part1 ????????????????
    ????? 18 ??????? 185 ??????? 2543. ????215-217.
  • Avia Training and Consulting, LLC.
    http//www.avia-training.com/tcl-overview.html.
    online. 28-1-44.
  • Eric Foster-Johnson. Graphical Applications with
    Tcl and Tk. http//www.pconline.com/erc/tclbook.h
    tm. online. 29-1-44
  • Brent Welch. The 2nd Edition of Practical
    Programming in Tcl and Tk . http//www.beedub.com/
    book/2nd/booktoc.mif.html. online. 28-1-44.
  • Tcl Developer Xchange. An Introduction to Tcl
    Syntax. http//www.scriptics.com/scripting/syntax.
    html. online. 28-1-44.
  • Tcl Developer Xchange. Tcl Primer.
    http//www.scriptics.com/advocacy/primer.html.
    online. 28-1-44.

EXIT
MAIN MENU
gt
lt
Write a Comment
User Comments (0)
About PowerShow.com