环境及版本说明:

OSX10.9

tclsh -> tclsh8.5

wish -> wish8.5

查看本机运行环境:

1 which wish;
2 /usr/bin/wish

1 which tclsh;
2 /usr/bin/tclsh

Demo功能说明:

用户登录窗口,输入用户名,密码.与文件中存储内容校验,如果相等,则提示"登录成功",否则提示"是否需要新建用户",点击"否"退出messageBox,点击"是"新建用户.内容追加写入文件.

  1 #!/usr/bin/wish -f
  2 #
  3 # this is test login, Tk-style
  4
  5 set filename "usrfile.pwd";
  6
  7 proc splitf { str index } {
  8     set y [ split $str | ];
  9     list  $y;
 10     set w [ lindex $y $index ];
 11     return $w;
 12 }
 13
 14 proc checkinfo {name pwd} {
 15     global filename;
 16     set iflag 0;
 17     set isUser 0;
 18
 19     if { $name eq "" || $pwd eq "" } {
 20         return 005;
 21     }
 22
 23     set fileId [ open $filename r ];
 24     while { [ gets $fileId line ] >= 0 } {
 25         set nameInfile [ splitf $line 0 ];
 26         set cmp [ string compare $name $nameInfile ];
 27
 28         if { $cmp != 0 } {
 29             set isUser [ expr $isUser + 1 ];
 30         } elseif { $cmp == 0 } {
 31             set pwdInfile [ splitf $line 1 ];
 32             set cmp [ string compare $pwd $pwdInfile ];
 33             if { $cmp == 0 } {
 34                 close $fileId;
 35                 return 001; #login successful
 36             } else {
 37                 close $fileId;
 38                 return 004; #err user pwd
 39             }
 40         }
 41         set iflag [ expr $iflag + 1 ];
 42     }
 43     close $fileId;
 44
 45     if { $iflag == 0 } {
 46         return 002; #file is null,creat user;
 47     }
 48     if { $iflag == $isUser } {
 49         return 002; #creat user
 50     }
 51 }
 52
 53 proc process { uname pwd } {
 54     global filename;
 55     set returnCheck [ checkinfo $uname $pwd ];
 56     switch -- $returnCheck {
 57         001 { tk_messageBox -type ok -message "you are login successful" }
 58         002 { set answer [ tk_messageBox -type yesno -icon question \
 59                  -message "you need creat a user" ] ;
 60                 switch -- $answer {
 61                     no { }
 62                     yes { puts stdout [ createusr $uname $pwd ] }
 63                 }
 64             }
 65         //003 { tk_messageBox -type ok -icon warning -message "$filename file is null" }
 66         004 { tk_messageBox -type ok -icon error -message "input err of user pwd" }
 67         005 { tk_messageBox -type ok -icon info -message "user and pwd is not null" }
 68         default { tk_messageBox -type ok -icon error -message "system err" }
 69     }
 70 }
 71
 72 proc createusr { uname pwd } {
 73     global filename;
 74     set fileId [ open $filename a ];
 75     puts $fileId "$uname|$pwd" ;
 76     close $fileId;
 77     return 1;
 78 }
 79 wm title . LOGIN
 80 wm maxsize . 500 300
 81 wm minsize . 500 300
 82 wm resizable . 500 300
 83 wm geometry . 500x300+300+200
 84
 85 label .ulname -text "userName"
 86
 87 entry .tuname -textvariable name
 88
 89 label .ulpwd -text "userPwd"
 90
 91 entry .tupwd -textvariable pwd
 92
 93 button .bOK -text OK \
 94   -command { puts stdout [ process $name $pwd] }
 95
 96 button .bExit -text Exit \
 97   -command {exit}
 98
 99
100 place .ulname -x 110 -y 50
101 place .tuname -x 200 -y 50
102 place .ulpwd -x 110 -y 100
103 place .tupwd -x 200 -y 100
104
105 place .bOK -x 150 -y 150
106 place .bExit -x 280 -y 150

1 wish tk.tcl

配置文件格式:

1 cat usrfile.pwd2 userTmp|abc123

此Demo涉及控件,语法.足够日常使用.望对新学者有点帮助.

特别需要注意:

1- 所有的关键字与{ 等之间一定要有空格,否则无法解析.

错误: proc sum{arg1 arg2}{
正确: proc sum { arg1 arg2 } {

2- proc if switch等需要用{}包含的body 左括号一定要写到 if {} { 与关键字同行

1 proc sum { arg1 arg2 }
2
3 {
4
5   ....
6
7 }

以上代码将提示:

Error in startup script: wrong # args: should be "proc name args body"

while executing

"proc sum {arg1 arg2} "

(file "a.tcl" line 3)

需要修改为:

1 proc sum { arg1 arg2 } {
2
3   ....
4
5 }

学习网站:

http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

http://www2.tcl.tk/1062

http://blog.csdn.net/dulixin/article/category/366323

read-only access to git repository:

git clone https://github.com/galoishelley/tcltk

转载于:https://www.cnblogs.com/galoishelley/p/3411973.html

tcl/tk demo相关推荐

  1. Tcl/Tk入门(上)

    一.是什么(What)? TCL(Tool Command Language)是一种脚本语言,一种易于学习的动态程序语言.特点是:跨平台.开源.易扩展. Tcl Developer Site 站点对T ...

  2. Tcl/Tk脚本中执行Shell脚本

    在Tcl/Tk脚本中执行Shell命令 set n 0 set x "*"while {$n < 10} {puts $xset x "$x"*set n ...

  3. 把别人的Tcl/Tk代码加入到Go语言里12 游戏5 画图案?

    为什么80%的码农都做不了架构师?>>>    a 首先打开网页 http://wiki.tcl.tk/4206 b 把网页里提到的tcl/tk代码复制到如下go源代码的init_s ...

  4. linux 安装tcl命令,TCL/TK Linux下安装 | 勤奋的小青蛙

    原创文章,转载请注明: 转载自勤奋的小青蛙 本文链接地址: TCL/TK Linux下安装 在Linux下安装TCL/TK,可以有编译源代码的方式安装,也可以有直接通过二进制压缩包进行解压缩安装,本文 ...

  5. 把别人的Tcl/Tk代码加入到Go语言里2 矩形

    为什么80%的码农都做不了架构师?>>>    a 从互联网得到的一段tcl/tk代码,把她加入到go语言里 package main import "github.com ...

  6. Tcl/tk缩放Truetype字体时的精度问题

    最近有国内新客户抱怨我们产品显示的原理图太不专业了,在原理图上使用宋体GB2312设计好中文图表,经过几次缩放时,表格内的文字居然会跑到表格外边,更要命的是打印出来的文档也存在同样的问题. 我研究了一 ...

  7. linux tcl是什么系统,基于Linux 及Tcl / Tk 的数控系统人机界面的实现

    随着嵌入式系统的迅速发展和广泛应用,嵌入式Linux以其强大的性能和开放性,越来越被开发人员所推崇.现在,各种基于Linux的嵌入式系统已被用于各行各业中.其中,人们对基于嵌入式实时Linux平台的开 ...

  8. Perl/Tkx ---- tcl/tk文本组件text

    tcl/tk text组件命令解析 使用text组件对文件编辑 tcltk text组件命令解析 text命令创建文本组件 文本索引 文本标记 标记选项 标记优先级 标记绑定 搜索与替换 虚拟事件 撤 ...

  9. ubuntu12.04.4安装tcl/tk和Tkinter

    1. 问题描述:运行python文件时出现以下信息: cryhelyxx@ada:~/python_workspace$ python httpurl.py Traceback (most recen ...

最新文章

  1. vue中使用baidushare分享到微信无法显示bug解决方案
  2. 小白都能看懂的目前主流加密MD5验签
  3. Siverlight去掉ToolTip的白色边框
  4. jquery ajax json转换出错Invalid JSON
  5. 大数据集群搭建之节点的网络配置过程(二)
  6. mongodb 存储过程 遍历表数据_mongodb推荐存列表字段还是多条记录?
  7. Web开发入门型服务器使用心得
  8. matlab 无法终止,Matlab使用xlsread, xlswrite函数导致excel进程无法终止的问题
  9. 软件安全之Hook 技术 Inline Hook技术应用 TraceMe.exe
  10. vscode工作区是什么意思_VS Code中的“工作区”是什么?
  11. QT 打开PDF文件或图片
  12. matlab coder 4.0,利用MATLAB Coder将MATLAB代码生成C/C++代码
  13. CF446D. DZY Loves Games
  14. python print怎么用_Python学习路线分享Beeprint怎么用
  15. 李峋同款 爱心动态代码 步骤教程,可自定义修改自己喜爱照片背景(附代码)
  16. 基于java植物养护管理系统ssm
  17. 用Python破解有道翻译反爬虫机制
  18. 【T+】畅捷通T+软件,修改固定资产模块中已经使用卡片的资产编码。
  19. 编译原理课程设计-对pl0语言进行扩充
  20. Java学习视频资料

热门文章

  1. 浅谈jQuery的选择器
  2. C++ 学习杂谈:sizeof和sizeof(string)的问题
  3. python中del语句
  4. 使用el-checkbox实现全选,点击失效没有反应
  5. 1.KafKa-介绍
  6. Eclipse GBK批量转UTF-8插件(转)
  7. day212223:线程、进程、协程
  8. Servlet执行时要实现的方法
  9. 她说程序员不懂浪漫,生日宴上惨变单身狗,其实,程序员的浪漫你不懂!
  10. 数据存储和界面展示(二)