This is a command in the TclX package.

select readFileIds ?writeFileIds? ?exceptFileIds? ?timeout?

Discovers which channels are ready for reading, writing or have an exceptional condition pending. Each of readFileIds, writeFileIds and exceptFileIds is a list of channel handles (as produced by open or socket) to check for the given condition. The timeout is how long to wait (a floating-point number of seconds) for a response if none of the given channels currently are in any of the given states; if omitted, this command will wait indefinitely.

This mechanism is also the foundation of the fileevent command and Tcl's event loop on Unix. This command is constrained in what it can do on Windows.

Richard Suchenwirth 2007-12-13 - The verb select has many facets, a popular one being its use in SQL. Here I chose it for a slight abstraction over tk_chooseDirectory and tk_getOpenFile, mostly to escape from "quoting hell". It starts from the directory that the associated variable contains, and does not change the variable if canceled.

 proc select {what _var} {
    upvar #0 $_var var
    set res ""
    switch -- $what {
        dir  {set res [tk_chooseDirectory -initialdir $var]}
        file {set res [tk_getOpenFile -initialdir [file dir $var]]}
        default {error "usage: select dir|file"}
    if {$res ne ""} {set var $res}

Practical effect: while gaining the initial directory and cancel functionalities, calls like

     button $f.2 -text ... -command "set $varname \[tk_getOpenFile\]" 

could be simplified to

     button $f.2 -text ...  -command [list select file $varname]