5.11 Selecting Files

Tk provides for predefined dialogs to select files for being opened or for being saved.

Selecting a file to be opened can be done with the command tk_getOpenFile. For example, an arbitrary file can be selected as shown in Figure 5.11. If the command returns the empty string (that is nil), the selection dialog has been canceled. Otherwise, the string S gives the filename of the file to be opened.

case {Tk.return tk_getOpenFile}
of nil then skip 
elseof S then {Browse file({String.toAtom S})}

Figure 5.11: Selecting files.

The visual appearance of the file selector depends on the operating system Oz runs on. For example, the file selector for Unix based operating systems is shown in Figure 5.11. Running Oz under Windows uses the Windows specific file selector dialog.

To select filenames for saving the command tk_getSaveFile can be used in the same way as above. The difference is that this command does not require that a file with the selected filename already exists.

Reference information on both commands can be found in tk_getOpenFile.

Christian Schulte
Version 1.4.0 (20080702)