我的目标是做这样(简化)代码:
package require MyProcessor 0.1
package require Tk
proc Open_file {} {
MyProcessor::Process
}
# Upper frame
frame .top
# Input file name
set inp_file_name "Input file name (press button -->)"
label .top.lbInpFileName
button .top.btInpFile -text "..." -command Open_file
grid .top.lbInpFileName .top.btInpFile
# Two edits
text .inpTxt
text .outTxt
grid .inpTxt
grid .outTxt
vwait ::MyProcessor::inp_file_name
vwait ::MyProcessor::lines
在myprocessor.tcl
中proc Process {} {
set inp_file_name [[tk_getOpenFile -initialdir "./"]
read_lines
set lines [Proceed $inp_lines]
}
虽然处理变量inp_file_name和行正在改变,我想在小部件中显示这些更改。这样做的方法是什么?
答案 0 :(得分:0)
这是上面示例的工作原型。您遇到的关键问题是标签没有将-textvariable
属性设置为inp_file_name
全局变量。文本行将插入MyProcessor :: Process过程中的文本小部件中。
namespace eval MyProcessor {
proc Process {} {
set file_name [tk_getOpenFile -initialdir "./"]
set h [open $file_name r]
set lines [read $h]
.inpTxt insert end $lines
close $h
return $file_name
}
}
proc Open_file {} {
global inp_file_name
set inp_file_name [MyProcessor::Process]
}
# Upper frame
frame .top
grid .top
# Input file name
set inp_file_name "Input file name (press button -->)"
# Set the textvariable attribute to the global inp_file_name variable.
label .top.lbInpFileName -textvariable inp_file_name
button .top.btInpFile -text "..." -command Open_file
grid .top.lbInpFileName .top.btInpFile
# Two edits
text .inpTxt
text .outTxt
grid .inpTxt
grid .outTxt