Version 16 of getOpenFile

Updated 2003-09-08 20:47:56

The functions tk_getOpenFile and tk_getSaveFile are documented in the http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/getOpenFile.htm and implemented in the Tk package library file tk.tcl .

On Windows, it calls a native file selector. You can get the Tcl-coded "original" as used on Unix/Linux by explicitly calling

 set filename [::tk::dialog::file:: open arg arg..]

Note that the command name is the empty string in its namespace. Any other value than open for the first argument calls the equivalent of getSaveFile. (RS)


tkfbox [L1 ] is a nifty little portable bundle for extending get{Open,Save}File capabilities.

This grabbed my attention because of my recent TIP regarding sub-classing the file dialogs on UNIX (well, non-Windows platforms). But there isn't enough documentation to tell what the benefits of this file are. -- CLN 2001-10-19


tkfbox was originally from sun, but partially reworked by me (Mick O'Donnell). I was recently asked why I used it rather than the now standard tk_getOpenFile/tk_getSaveFile. Well, I have so far found 4 advantages of pure the tcl/tk code versions:

  • Can set background colors to the window: the built-in versions are limited to a gray background. the tkfbox version uses the default background color.
  • Doesn't fall prey to the bug in the built in version which means that double clicks on a file name are not totally consumed, and can cause a click event on a widget below the open file dialog. This can be patched, but it is a problem.
  • When you call the tkfbox tk_getSaveFile with multiple filetypes specified, and change the filetype using the filetype listitem, then the displayed filename will change its extension. E.g., changing from jpg to gif will also change the filename's extension. This doesnt happen with the built in tk_getSaveFile.
  • The real advantage is that since the tkfbox version is tcl/tk code, I can adapt it at will. If there is some feature I don't like in the built-in version, I can change/add/delete the feature.

Mick mailto:[email protected]

DKF - As the maintainer of (the script versions of) the standard dialogs, I'd love to have suggestions of how to improve them, so long as these improvements are things that are not too hostile to operating in a cross-platform manner (note that the official script-level API is pretty-much fixed; the Windows native dialogs are not very capable!)

MGS With tk_getSaveFile and tk_chooseDirectory, you should be able to create directories.

DLR Suggestions for improvement: Change the default icons for folders and files, they look rather ugly. I use the ones that come with BWidgets. Ability to select multiple files.


JBR 2003-09-08 - I have extended the tkfbox code to include some new options. You can find it here[L2 ]

 -blueplate separates the dirs into one IconList and the files into another.
 -colormap  allows the file dialog to use the colormap of a parent window.
 -dirslist  take a list of "standard" directories and puts them at the top of the dir popup.
 -filetype  enables a secret global parameter controlled by an additional file type popup menu.

I have just recently merged these extensions with the 8.4 tkfbox that allows multiple files to be selected. We use all these extended options in the ds9 image display program.


Category Dialog - Tk syntax help - Arts and Crafts of Tcl-Tk Programming