每当在 tcl 中选择表列表中的项目时发出命令?
Command whenever an item in a tablelist is selected in tcl?
我有一个表格列表,我想在某处显示当前所选项目的信息。就像突触的 (pic)
这是我的表格:
tablelist::tablelist .t.frm.lbf.mlb -selectmode multiple -columns {0 "File" 0 "Name" 0 "Version" 0 "Archtectures" 0 "Summary" 0 "Type"} \
-stretch all -background white -width 57 -xscroll {.t.frm.lbf.h set} -yscroll {.t.frm.lbf.v set} -showseparators true
因此,只要单击(选择)一行,它就会显示信息
我找不到如何将命令绑定到项目单击(选择)。
就像我在评论中提到的那样,您可以使用 [.tbl bodytag]
的绑定来在 table 列表正文中单击时触发功能。对于您的示例:
bind [.t.frm.lbf.mlb bodytag] <Button-1> {
lassign [tablelist::convEventFields %W %x %y] w x y
lassign [split [$w containingcell $x $y] ,] row col
tk_messageBox -title Info -message "This is $row,$col"
}
将显示一个消息框,说明正在单击哪个 table 单元格。从 table 单元格中,您可以获得 table 行 $row
。从 table 行,您可以获取该行上任何单元格的单元格内容。
例如在图片中,单击第一行的任意位置会给 $row
值 0。您可以通过调用类似以下内容来获取包名称:
set pkgName [lindex [lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4] 2]
这将为您提供值 openoffice.org-calc
,然后您可以使用该值来获取要在不同小部件中显示的任何信息。
[.t.frm.lbf.mlb rowconfigure $row -text]
给出行 $row
.
中的所有文本设置
[lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4]
仅在 tcl 列表中给出该行的文本值。
[lindex [lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4] 2]
然后给出第 3 列(索引 2)的文本值。
将脚本绑定到表格列表小部件的 <<TablelistSelect>>
虚拟事件,并在事件处理程序中使用 .tablelist curselection
来检索选定的索引。请务必为您的列提供一个 -name 属性,以便即使用户更改列顺序也可以轻松定位单元格:
.t.frm.lbf.mlb columnconfigure 0 -name file
bind .t.frm.lbf.mlb <<TablelistSelect>> [list packageSelected %W]
proc packageSelected {w} {
# -selecttype row is the default
foreach row [$w curselection] {
puts [format "Package file %s selected" [$w getcells $row,file]]
}
}
我有一个表格列表,我想在某处显示当前所选项目的信息。就像突触的 (pic)
这是我的表格:
tablelist::tablelist .t.frm.lbf.mlb -selectmode multiple -columns {0 "File" 0 "Name" 0 "Version" 0 "Archtectures" 0 "Summary" 0 "Type"} \
-stretch all -background white -width 57 -xscroll {.t.frm.lbf.h set} -yscroll {.t.frm.lbf.v set} -showseparators true
因此,只要单击(选择)一行,它就会显示信息
我找不到如何将命令绑定到项目单击(选择)。
就像我在评论中提到的那样,您可以使用 [.tbl bodytag]
的绑定来在 table 列表正文中单击时触发功能。对于您的示例:
bind [.t.frm.lbf.mlb bodytag] <Button-1> {
lassign [tablelist::convEventFields %W %x %y] w x y
lassign [split [$w containingcell $x $y] ,] row col
tk_messageBox -title Info -message "This is $row,$col"
}
将显示一个消息框,说明正在单击哪个 table 单元格。从 table 单元格中,您可以获得 table 行 $row
。从 table 行,您可以获取该行上任何单元格的单元格内容。
例如在图片中,单击第一行的任意位置会给 $row
值 0。您可以通过调用类似以下内容来获取包名称:
set pkgName [lindex [lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4] 2]
这将为您提供值 openoffice.org-calc
,然后您可以使用该值来获取要在不同小部件中显示的任何信息。
[.t.frm.lbf.mlb rowconfigure $row -text]
给出行 $row
.
[lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4]
仅在 tcl 列表中给出该行的文本值。
[lindex [lindex [.t.frm.lbf.mlb rowconfigure $row -text] 4] 2]
然后给出第 3 列(索引 2)的文本值。
将脚本绑定到表格列表小部件的 <<TablelistSelect>>
虚拟事件,并在事件处理程序中使用 .tablelist curselection
来检索选定的索引。请务必为您的列提供一个 -name 属性,以便即使用户更改列顺序也可以轻松定位单元格:
.t.frm.lbf.mlb columnconfigure 0 -name file
bind .t.frm.lbf.mlb <<TablelistSelect>> [list packageSelected %W]
proc packageSelected {w} {
# -selecttype row is the default
foreach row [$w curselection] {
puts [format "Package file %s selected" [$w getcells $row,file]]
}
}