如何在tcl-tk中显示目录结构(explorer)?

如何在tcl-tk中显示目录结构(explorer)?,tcl,directory,hierarchy,tk,Tcl,Directory,Hierarchy,Tk,我无法在treectrl中递归添加节点。i、 我想在浏览器中显示所有的目录和文件 到现在为止,这就是我所拥有的。我目前正在每个文件夹中添加虚拟节点 package require treectrl treectrl .t -showheader 0 -selectmode single -showroot 0 -yscrollcommand {.y set} scrollbar .y -ori vert -command ".t yview" pack .y -side right -fill

我无法在treectrl中递归添加节点。i、 我想在浏览器中显示所有的目录和文件

到现在为止,这就是我所拥有的。我目前正在每个文件夹中添加虚拟节点

package require treectrl
treectrl .t -showheader 0 -selectmode single -showroot 0 -yscrollcommand {.y set}
scrollbar .y -ori vert -command ".t yview"
pack .y  -side right -fill y
pack .t  -side right -fill both -expand 1
set columnID [.t column create -text "Column 0"]
.t configure -treecolumn $columnID
.t element create el1 text 
.t element create el2 rect -showfocus yes
.t style create s1
.t style elements s1 [list el1 el2]
.t style layout s1 el2 -union el1
.t configure -defaultstyle s1

proc add_node {parent text} {
    set itemID [.t item create -button yes ]
    .t item element configure $itemID 0 el1 -text $text
    .t item collapse $itemID
    .t item lastchild $parent $itemID
    return $itemID    
}

set images [glob -nocomplain -directory "D:/Explore" "*"]
for {set i 0} {$i<=[llength $images]} {incr i} {
    set root [lsearch $images [lindex $images $i]]
    add_node [add_node [add_node root [list directory [file tail [lindex $images $i]]]] dummy] dummy2
}
软件包需要treectrl
t-showheader 0-selectmode single-showroot 0-yscroll命令{.y set}
滚动条.y-ori vert-command“.t yview”
包装。y-右侧-填充y
包装.t-右侧-两侧填充-展开1
设置columnID[.t列创建-文本“列0”]
.t configure-treecolumn$columnID
.t元素创建el1文本
.t元素创建el2 rect-showfocus是
.t样式创建s1
.t样式元素s1[列表el1 el2]
.t型布局s1 el2-活接头el1
.t配置-默认样式s1
proc add_节点{父文本}{
设置项目ID[.t项目创建-按钮是]
.t项目元素配置$itemID 0 el1-文本$text
.t项目折叠$itemID
.t项目lastchild$parent$itemID
返回$itemID
}
设置图像[glob-nocomplain-directory“D:/Explore”“*”]

对于{set i 0}{$i首先,您需要使用
glob
命令的选项
-tipes
。这样您可以分离目录和文件。其次,您需要递归来处理嵌套的文件和目录

package require Tk
package require treectrl
treectrl .t -showheader 0 -selectmode single -showroot 0 -yscrollcommand {.y set}
scrollbar .y -ori vert -command ".t yview"
pack .y  -side right -fill y
pack .t  -side right -fill both -expand 1
set columnID [.t column create -text "Column 0"]
.t configure -treecolumn $columnID
.t element create el1 text
.t element create el2 rect -showfocus yes
.t style create s1
.t style elements s1 [list el1 el2]
.t style layout s1 el2 -union el1
.t configure -defaultstyle s1

proc add_node {parent text button} {
    set itemID [.t item create -button $button ]
    .t item element configure $itemID 0 el1 -text $text
    .t item collapse $itemID
    .t item lastchild $parent $itemID
    return $itemID
}

proc add_directory {path parent} {
  set directory_list [glob -nocomplain -types d -directory $path "*"]
  foreach directory $directory_list {
    set n [add_node $parent [file tail $directory] yes]
    add_directory $directory $n
  }
  set files_list [glob -nocomplain -types f -directory $path "*"]
  foreach file $files_list {
    set n [add_node $parent [file tail $file] no]
  }
}

add_directory "D:/Explore" root

您可能需要仔细阅读中列出的项目以获得灵感