The tk_chooseDirectory
command displays a dialog window that allows the end user to select a directory, as the name implies. The return value is the absolute directory path selected or an empty string (if the Cancel button is clicked).
The syntax is as follows:
tk_chooseDirectory option value …
The tk_chooseDirectory
command accepts one or more option value
pairs as detailed below. If no option value pairs are provided, the command will display the default values for the dialog.
Option |
Interpretation |
---|---|
|
Sets the initial directory to display. If not set, the current working directory will be displayed. |
|
Specifies if the user may specify a non-existing directory. |
|
Specifies the parent of the dialog. The dialog is displayed on top of the parent. |
|
Sets the text to be displayed in the dialog title bar. |
In the following example, we will display a message box and assign the return value to a named variable. Enter the following commands:
1 % set response [tk_chooseDirectory -initialdir ~ -title "Select a
Directory"]
You should now see a similar dialog displayed, based on your display manager.
Note that in your shell window, the input line is no longer active. This is due to the fact that the application (in this case, the wish shell) is awaiting a response. Select a directory (in this case I have selected my home directory) and click on the OK button and you will notice that full path for the directory selected is displayed. Enter the following command to confirm that the symbolic value was assigned to the named variable:
2 % puts $response
C:/Documents and Settings/Bert
18.191.237.194