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_***

#}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章