Tcl如何在这个脚本中显示名称?

时间:2017-03-31 16:24:42

标签: linux bash tcl

我使用tcl但我不知道如何使用此脚本代码显示字符串字母数字

  
#!/usr/bin/wish
 
wm title . "Feet to Meters"
grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1

grid [ttk::entry .c.feet -width 7 -textvariable feet] -column 2 -row 1 -sticky we
grid [ttk::label .c.meters -textvariable meters] -column 2 -row 2 -sticky we
grid [ttk::label .c.meter2s -textvariable meters2] -column 6 -row 2 -sticky we
grid [ttk::button .c.calc -text "Calculate" -command calculate] -column 3 -row 3 -sticky w
grid [ttk::entry .c.feet2 -width 7 -textvariable feet2] -column 7 -row 1 -sticky we

grid [ttk::label .c.flbl -text "feet"] -column 3 -row 1 -sticky w
grid [ttk::label .c.flbl2 -text "feet2"] -column 6 -row 1 -sticky w
grid [ttk::label .c.islbl -text "is equivalent to"] -column 1 -row 2 -sticky e
grid [ttk::label .c.mlbl -text "meters"] -column 3 -row 2 -sticky w
grid [ttk::label .c.mlbl2 -text "meters2"] -column 4 -row 2 -sticky w

foreach w [winfo children .c] {grid configure $w -padx 5 -pady 5}
focus .c.feet
bind . <Return> {calculate}

proc calculate {} {  
   if {[catch {
       set ::meters [expr {round($::feet*0.3048*10000.0)/10000.0}]
       set ::meters2 [ feet2 ]
   }]!=0} {
       set ::meters ""
   }
}

在此部分中,脚本失败

in this part the script fails

   set ::meters2 [ feet2 ]

我想在写入文本时显示feet2值并按下计算

请帮帮我

1 个答案:

答案 0 :(得分:1)

喜欢这个吗?

proc calculate {} {
   if {[catch {
       set ::meters [expr {round($::feet*0.3048*10000.0)/10000.0}]
       set ::meters2 $::feet2
   }]!=0} {
       set ::meters error
       set ::meters2 error2
   }
}