Displaying the directory dialog

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

-initialdir directory

Sets the initial directory to display. If not set, the current working directory will be displayed.

-mustexist boolean

Specifies if the user may specify a non-existing directory.

-parent window

Specifies the parent of the dialog. The dialog is displayed on top of the parent.

-title string

Sets the text to be displayed in the dialog title bar.

How to do it…

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.

How to do it…

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

How it works…

Based on the option value pairs provided, Tk has displayed a tk_chooseDirectory with the messages and buttons desired. On completion, the return value was assigned to a named variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.194