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 ...

Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.