#1611 The first call to tk_get*File modifies the following calls

obsolete: 8.4.4

On tk-8.4.4 installed on Linux RedHat 7.2 kernel
2.4.20, the first time you call tk_get*File -filetypes
"typelist", the program sets the global variable
data(extUsed) to indicate if -defaultextension option
has been used with a non-empty value (see file
tkfbox.tcl of the standard tk release 8.4.4 line1356
and its 2 following blocks). No subsequent calls of
tk_get*File -filetypes "typelist" will change the
original value of data(extUsed) and the decision to use
the -defaultextension option will always depend on the
first call to tk_get*File -filetypes "typelist".

For example, test.tcl:

proc save_as {} {
set typelist {
{{Text} {.txt}}
{{All} {*}}
set file [tk_getSaveFile -defaultextension .exe
-filetypes $typelist]
puts $file

pack [button .save -text "Save as" -command save_as]
pack [button .quit -text Quit -command exit]
set file [tk_getOpenFile -filetypes {"All *"}]
puts $file

"wish test.tcl" will add the extension .txt instead of
.exe when the user press the "Save as" button and type
a file without extension. This is due to the fact that
the call to tk_getOpenFile did not use the
-defaultextension option and the program will always
consider that this option is not used when tk_get*File
is called after. Commenting out the last two lines of
the program will let the program behaves as it should.

My suggestion is to delete the lines 1356 and 1362 ("if
{![info exists data(extUsed)]} {" and "}") of the file
tkfbox.tcl to reset data(extUsed) EVERYTIME tk_get*File
is called according to the value of the current
-defaultextension option value.

Michel Pitermann


  • Jeffrey Hobbs
    Jeffrey Hobbs

    • assigned_to: hobbs --> dkf
  • Logged In: YES

    The problem relates to how to reconcile the
    -defaultextension and the -filetypes options, and is
    surprisingly nasty (i.e. I've tinkered with this a few
    times, and the current behaviour seemed to be not too
    surprising to users when I put it into production
    applications; they seem to expect selecting the type to set
    the default extension for some reason.) Clearly it could be
    improved though.

    • status: open --> closed-fixed
  • Logged In: YES

    Fixed in HEAD and 8.4 branch