tcltk编程及应用简介课件.pptx
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《tcltk编程及应用简介课件.pptx》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- tcltk 编程 应用 简介 课件
- 资源描述:
-
1、OutlinesTcl/Tk Around UsTcl/Tk OverviewBasic Tcl SyntaxIntroduction for TkIntroduction for ExpectHomebrew Test Automation FrameworkThe SUR of TAO ProjectResourcesTcl/TkAround UsFrom WorkPlaceIn WCS In ITE/8610 Using Expect to communicate with WCS:send CLI commands and get response.In Cisco IOSRouter
2、enableRouter#tclshRouter(tcl)#puts$tcl_version8.3Test Automation for Telecommunication and Network Equipments To Our Daily LifeIts easy to design handy programs based on Tcl to fulfill different tasks A fish screen save program A e-piano A Painting padFishPIANOTexpict.tclTcl/TkOverview-Say“tickle te
3、e-kay”Whats TclTcl stands for Tool Command Language Joh Ousterhout,University of California.First release was in 1989.A simple scripting language:Cross platform support.Tcl can run on most popular operation system such as unix/linux,Windows,Macintosh and so forth Scripts are interpreted at run time.
4、Which makes the development cycle faster than compiled languages,no waiting for long compilations The capability to call C/C+routines Similar to other shell languages such as UNIX C shell,Perl,VB.“”to study Excellent text analysis competenceWhats Tcl(cont)Un-typed and a string-based command language
5、 Data types are not used when variables are defined.You neednt specify a variable as integer,float or a string.The basic mechanisms are all related to strings and string substitutions All variables are stored as strings.automatic type conversion in contextset x 10;#create a variable“x”and give a val
6、ue“10”to itset y 20;#create a variable“y”and give a value“20”to itset z expr$x+$y;#x plus y and save result in“z”set y“Im a string now.Indeed Im always string:-)”puts“Expression result is:$z”;#print result on standard outputs“Y becomes as:”$y”set aArray“Jack boy Merry girl”;#define an arrayputs“Im a
7、n array,but a string indeed:n$aArray”Whats Tcl(cont)Easy to extend There are numerous free extensions built on top of Tcl/Tk for specific functions available on the Internet.Tclx:Handling signal events Net-Snmp:support snmp communinication BWidget/IWidget etc.:Tk extensions provides special and powe
8、rful widgets Http&ncgi:for http server programming It is easy to add new Tcl primitives by writing C procedures Tcl/Tk is Pure C Open-Source code,new Tcl commands can be implemented by specific extensions programmed in C,fairly easy without changing Tcl core.Totally Free!Whats TkTk A Tcl-based toolk
9、it for programming graphical user interfaces Quick and easy to build powerful user interfaces.Portable,one copy of script can work unchanged on UNIX,Windows,and the Macintosh.Whats ExpectExpect A Tcl-based Toolkit for Automating Interactive Programs The program interactively prompt and expect user t
10、o enter keystrokes in response A default command in some operation systems Theres also an Expect extension for tcl which can also be loaded to tcl shellTcl not so good newsInterpreted languages run slower and use more processing time or overheadWithout a complier,syntax errors cant be found until th
11、e script is executedUn-typed languages do not allow for the most efficient translation of codeBasic Tcl SyntaxTcl Commands FormatA Tcl script consists of one or more commands Commands are separated by newlines or semi-colons A script with two commands separated by a newline character:set a 24set b 2
12、5 Above script could be written on a single line using a semi-colon separator:set a 24;set b 25 Basically each command consists of one or more words First word is the name of a command Additional words are arguments to that command Words are separated by spaces and tabs var1 var2 VariableNeednt decl
13、are the type of variable,automatic conversion in contextset x“10.99”;#this is a stringputs“expr int($x)”;#output would be 10Need to be declared and assigned a value before useVariable name is case-sensitiveAssignment expression:set To use value of a variable,put a“$”ahead of it as$If you want to app
14、end extra characters to a variable,use braces around variable name as:set x“Hello ”puts“$xJack!”;#This is wrong,it would treat xJack as variable nameputs“$xJack!”;#This is right!Different scopes should share variable values by specific methods.namespace procedure To use global to visit global variab
15、les children interpreterCommentsComment is set in a shell way,leading by a“#”set a(“john”)boy;#Set value of element“john”of array“a”as“boy”#Or we can do asarray set a“john boy”;#If you lik,you cancomment using multi-linesBe careful when add comments to a“switch”expressionswitch var“go”to handle go#I
16、f it does not support following value,comment it later:=Wrong!“pause.Standard Output&InputI/O operation for standard input and output,normally the terminal in front of us.Print out on terminal:puts“abcdefg No Thanks.”Format the string by using“format”command Similar as Cset str format“%-2d%20s%9d”,1
17、93 is not equal to 0133;#octal number“193 is not equal to 91”Get input:puts-nonewline“Your name please:”gets stdin sNameMath and Logical Expressionexpr expr expr 1+2;set x 10;set y 20;expr$x+$y=30expr abs(-10)=10expr 10*rand()=9.06197207004855;#result is double,0 value 5;#in range of 07incrset x 1in
18、cr x=2incr x 3=5incr x-2=3 logic“and”“or”.Control:Branch and LoopIf.elseif.else.if Boolean expression if xxx else if xxx elseif else Forset sum 0;for set i 0;set y 10$i 450Whilewhile gets$fd line=0 Switchswitch-exact$xyz“0”;?break?;“1”?default?Foreach(refer to operation of list)List,Array&Operation“
19、list”represent a list of string Commands for listlist,lindex,lrange,lappend,lreplacesplit,join Array is similar as the“associate”array or hash data in perl or php.%set lst1“Jack boy blue Merry girl red”;#or%set lst2 list Red White Yellow Blue%foreach x$lst puts“$xn”%foreach x y z$lst1 puts student n
20、ame:$x,a$y,who likes$zstudent name:Jack,a boy,who likes bluestudent name:Merry,a girl,who likes redputs lindex$lst2 2=Whiteputs lindex$lst2 0=Red%array set aArr list Jack boy Merry girl%parray aArraArr(Jack)=boyaArr(Merry)=girl%array get aArrJack boy Merry girl%array names aArrJack Merry%array size
21、aArr2%foreach x y array get aArr puts Name:$x,a$yName:Jack,a boyName:Merry,a girlString&Operation append format subst string commandn string comparen string matchn string equal(added in 8.4)n string rangen string tolower/touppern string trim string comparation:n if$str1=$str2 puts equaln string comp
22、aring commands such as“string match”string class check:n string isif string is integer 10 puts okProc and ReturnProcedure in tcl similar as function in C,perl,php,unix shell etc.proc arg1 arg2.args proc body return stringproc calc1 opa “opb 10”return expr$opa+$opb calc1 2 3=5calc1 2=12 proc calc2 ar
23、gs ;#Vary argument list set opa lindex$args 0 set opb lindex$args 1 return expr$opa+$opb global variable In a procedure,use“global”to make a global variable visible from inside of procedureFile I/OWrite file%set fd open abc w+=filef76ec0%puts$fd abcdn%puts$fd efgtn%flush$fd%close$fd Read file%set fd
24、 open abc r=filef840d8n Get file content line by line%while gets$fd line!=-1 puts-nonewline$line=abcd efgtn Read commandread?chunk bytes?set str read$fdwhile!eof$fd svet buf read$fd 10000 .Socket&File Eventsocket?-myaddr addr?-myport myport?-async?host portsocket-server command?-myaddr addr?portNOTE
25、:“port”specified here is the“listening”port which cant be used to transfer data.As the connection request is accepted,a new socket will be created for transport data.proc Accept newSock addr port global sock_arrputs Accepted$newSock from$addr port$portset sock_arr(addr,$newSock)list$addr$portfconfig
展开阅读全文