【问题标题】:How can I update label through -textvariable如何通过 -textvariable 更新标签
【发布时间】:2015-07-24 22:46:24
【问题描述】:

我已经输入了这样的脚本:

set cmakeBinName "noname"
proc Get_CMakeBin { } {
    set cmakeBinName [ tk_getOpenFile -initialdir / ]
}
label .l  -text { CMake bin: }
label .lb -width 24 -textvariable $cmakeBinName
button .cmb -text "..." -command Get_CMakeBin
grid .l .lb .cmb

但对话框结束后标签中的文本不会更改。 如何改进脚本?

【问题讨论】:

    标签: tcl tk


    【解决方案1】:

    过程中的变量是局部变量,除非明确另有说明。试试这个:

    proc Get_CMakeBin { } {
        global cmakeBinName
        set cmakeBinName [ tk_getOpenFile -initialdir / ]
    }
    

    您还应该知道-textvariable 选项采用变量name,而不是contents。你应该这样写:

    label .lb -width 24 -textvariable cmakeBinName
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-09
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      相关资源
      最近更新 更多