TCL-TK界面

本文简单介绍tcl-tk,并附一个界面案例。最后上传了三个附件,关于tcl-tk编写的手册。

tck-tk手册在如下网页点击下载:http://pan.baidu.com/s/1jHXGXpW

首先,Tcl是一种简单的脚本语言,主要使用于发布命令给一 些互交程序如文本编辑器、调试器和shell。它有一个简单的语法 和很强可扩充性,Tcl可以创建新的过程以增强其内建命令的能力。

其次,Tcl是一个库包,可以被嵌入应用程序,Tcl的库包含了一个分析器、用于执行内建命令的例程和可以使你扩充(定义新的 过程)的库函数。应用程序可以产生Tcl命令并执行,命令可以由用户产生,也可以从用户接口的一个输入中读取(按钮或菜单等)。但Tcl库收到命令后将它分解并执行内建的命令,经常会产生递归的调用。

TK 是与 TCL 语言关系最密切、且被广泛使用的图形库,TCL 语言和 TK 都由 JohnOusterhout 开发。虽然 TK 于 1991 年作为 X11 库出现,但实际上它从那时起就被移植到每一种流行的 GUI。(它与 Python 逐渐拥有“标准”GUI 的情形相似。)现在,大多数流行语言和很多小型语言都有 TK 绑定(Tkinter 模块)。


本实例代码对应的界面截图

代码如下:

#wm title . "NS2环境中OLSR协议的研究及模拟"

grid [frame .f] -column 0 -row 0 -sticky nwes

grid columnconfigure . 0 -weight 1

grid rowconfigure . 0 -weight 1

 

#命名仿真文件

grid [label .f.laType -text "仿真文件命名" ] -column 1 -row 1 -sticky nwes

grid [entry .f.fileName -width 7 -textvariablefileName ] -column 2 -row 1 -sticky nwes

 

#选择拓扑类型

grid [label .f.latopotype -text "拓扑类型"]-column 1 -row 2 -sticky nwes

grid [radiobutton .f.line -text Line -variabletopotype -value Line] -column 2 -row 2 -sticky w

grid [radiobutton .f.matrix -text Matrix-variable topotype -value Matrix] -column 3 -row 2 -sticky w

grid [radiobutton .f.random -text Random-variable topotype -value Random] -column 4 -row 2 -sticky w

 

#选择协议

grid [label .f.laRout -text "协    议"] -column 1-row 3 -sticky nwes

grid [radiobutton .f.olsr -text OLSR -variableroupro -value OLSR] -column 2 -row 3 -sticky w

grid [radiobutton .f.aodv -text AODV -variableroupro -value AODV] -column 3 -row 3 -sticky w

grid [radiobutton .f.dsr -text DSR -variableroupro -value DSR] -column 4 -row 3 -sticky w

 

#输入节点数量

grid [label .f.laNodeNum -text "节点数量"]-column 1 -row 4 -sticky nwes

grid [entry .f.nodeNum -width 7 -textvariablenodeNum ] -column 2 -row 4 -sticky w

 

#输入产生流量节点数量

grid [label .f.laNodeNum2 -text "产生流量节点数量"] -column 3 -row 4 -sticky nwes

grid [entry .f.lanodeNum -width 7-textvariable lanodeNum ] -column 4 -row 4 -sticky w

 

#生成节点总数

grid [label .f.laNodeNum3 -text "发送数据包总数"] -column 1 -row 5 -sticky nwes

grid [entry .f.allnode -width 7 -textvariableallnode ] -column 2 -row 5 -sticky w

 

#设置网络接口队列大小

grid [label .f.laqlen -text "接口队列大小"] -column 3 -row 5 -sticky nwes

grid [entry .f.qlen -width 7 -textvariableqlen ] -column 4 -row 5 -sticky w

 

 

#选择流量类型

grid [label .f.laTcpUdp -text "Cbr流量类型"]-column 1 -row 6 -sticky nwes

#grid [radiobutton .f.cbr -text Cbr -variableflowType -value cbr] -column 2 -row 6 -sticky w

grid [radiobutton .f.tcp -text Tcp -variableflowType -value tcp] -column 2 -row 6 -sticky w

grid [radiobutton .f.udp -text Udp -variableflowType -value udp] -column 3 -row 6 -sticky w

 

# 设置发送包大小

grid [label .f.lapacketsize -text"packetsize"] -column 1 -row 7 -sticky nwes

grid [entry .f.packetsize -width 7-textvariable packetsize ] -column 2 -row 7 -sticky w

grid [label .f.danwei -text "字节"]-column 3 -row 7 -sticky w

#是否启用nam

grid [label .f.lanam -text "运行nam"]-column 1 -row 8 -sticky nwes

grid [radiobutton .f.isnam -text isnam-variable isnam -value isnam] -column 2 -row 8 -sticky nwes

grid [radiobutton .f.nonam -text nonam-variable isnam -value nonam] -column 3 -row 8 -sticky nwes

#选择连接的颜色

grid [label .f.laColor -text "链接颜色"]-column 1 -row 9 -sticky nwes

grid [radiobutton .f.red -text red -variablecolor -value red] -column 2 -row 9 -sticky w

grid [radiobutton .f.blue -text blue -variablecolor -value blue] -column 3 -row 9 -sticky w

grid [radiobutton .f.yellow -text yellow-variable color -value yellow] -column 4 -row 9 -sticky w

 

#查看结果按钮

 

grid [button .f.save -text "保存设置"-command prWrite] -column 1 -row 10 -sticky nwes

grid [button .f.run -text "运行程序"-command prRun] -column 2 -row 10 -sticky nwes

grid [button .f.throughPutR -text "吞吐量查看"-command prThroughPutR] -column 3 -row 10 -sticky nwes

#grid [button .f.throughPutP -text "吞吐量绘图"-command prThroughPutP] -column 4 -row 7 -sticky nwes

#grid [button .f.delay -text "时延"-command prDelay] -column 3 -row 7 -sticky nwes

 

#

#随机生成两个节点产生流量

#

set ::nodeNum 6

set ::lanodeNum 3

set ::allnode 10000

set ::qlen 500

set ::packetsize 1000

set ::topotype Line

set ::roupro OLSR

set ::color red

 

proc prWrite {} {

#将图形界面中选择的数据写入到一个中间文件中

#在tcl主程序中读取这个文件中的数据,进行设置

     setf [open ./myvalues w]

    puts $f $::fileName

    puts $f $::topotype

    puts $f $::roupro

    puts $f $::nodeNum

    puts $f $::lanodeNum

    puts $f $::allnode

    puts $f $::qlen

    puts $f $::flowType

    puts $f $::packetsize

    puts $f $::color

    close $f

}

 

#数据分析

proc prRun {} {

    execsh runall.sh & exit 0

#}

proc prThroughPutR {} {

    execsh readresult.sh & exit 0

}

#proc prThroughPutP {} {

#   execgnuplot -p -e "set xlabel '时间(s)';set ylabel '吞吐量(kb)'; plot 'throughput_OLSR' with lines,'throughput_AODV' with#lines,'throughput_DSR' with lines"

#}

#proc prDelay {} {

#   execgnuplot -p -e "set xlabel '时间(s)';set ylabel '延迟(s)'; plot 'delay_OLSR' with lines,'delay_AODV' withlines,'delay_DSR' with #lines"      gawk–f throughput.awk olsr_wireless.tr > throughput_***

#}

 

  • 10
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值