Selecting a directory and file
In the following example, we will see how simple it is to combine the functionality of the tk_chooseDirectory
dialog (which returns only a directory listing) with the tk_getOpenFile
dialog (which returns a full file path) to assign the directory in use and the file selected to separate variables. This will be accomplished by the Tcl file command in combination with the tk_getOpenFile
dialog. I use this to allow a user to select or define a configuration file and default directory without requiring the use of two separate dialogs.
How to do it…
In the following example we display a File Selection dialog box and assign the return value to a named variable as well as strip out the directory and assign this to a second named variable. Enter the following commands:
1 % set response [tk_getOpenFile -filetypes $types]
You should now see the following dialog displayed.
Note that in your shell window the input line is no longer active. This is due to the fact that the...