使用trace在TCL中执行proc

时间:2013-05-08 10:26:30

标签: tcl trace

我在TCL / Tk应用程序中有以下内容:

 proc greyout { } {
     puts "current part $DSM::Part"
     switch $DSM::Part {
 Doghouse {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry  configure -state disabled
         .dsm.traceLATpart$entry  configure -state disabled
         .dsm.traceStowage$entry  configure -state disabled      
         .dsm.traceDoghouse$entry configure -state enabled}
        }
  Stowage {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry configure -state disabled
         .dsm.traceLATpart$entry configure -state disabled
         .dsm.traceStowage$entry configure -state enabled        
         .dsm.traceDoghouse$entry configure -state disabled}
        }   
     }   
 }

  trace add variable DSM::Part write greyout

每次“Part”更改trace trys以调用greyout但我收到以下消息:

 wrong # args: should be "greyout"
 wrong # args: should be "greyout"
 while executing
"greyout Part {} write"
(write trace on "Part")
invoked from within
"variable Part "CTR_Partition""
(in namespace eval "::DSM" script line 3)
invoked from within.....

我不知道为什么?!有任何帮助吗?

1 个答案:

答案 0 :(得分:1)

问题在于,当触发跟踪回调时,会在回调中附加额外的参数,这些参数用于提供有关触发回调触发的信息。因为您的代码只是对单个变量进行跟踪,所以这些参数目前对您来说并不是很有用,但它们在更复杂的情况下会有很多帮助。

调整代码来处理这个问题的最简单方法是使greyout使用特殊args形式参数获取任意数量的参数:

proc greyout {args} {
    puts "current part $DSM::Part"
    ...
}