console-problem on Windows

HJG I'm not sure if this is a bug, so here is a demo for a problem with console on Windows, when the main toplevel window is not shown, e.g. with wm withdraw, so that its close-button cannot be reached.

Exiting the program via the close-button of the console leaves a running wish85-shell behind.

To get rid of them, you need to use the taskmanager, or an utility like process-explorer.

To prevent this, include this statement with wm withdraw:

  console eval {wm protocol . WM_DELETE_WINDOW {exit} } 

However, exiting the program via the console-menu File/Exit works correctly, shutting down the remaining wish85 as expected.

Is there a reason for this different behaviour of close-button and File/Exit ?


 # https://wiki.tcl-lang.org/27957
 # console-problem on Windows 
 # 2011-02-12

   catch {console show}
   catch {wm withdraw .}
 # Alternative:
 #  wm geometry . 1x1+0+0
 #  wm overrideredirect . 1
 #  wm transient .

 # console eval {wm protocol . WM_DELETE_WINDOW {exit} } 

 # Fill the console with some info:
 # See also https://wiki.tcl-lang.org/839 : [Finding Out Your Processor and Operating System Configuration]
   puts "Console:"
   puts "title         : [wm title .]"
   puts "winfo visualid: [winfo visualid .]"

   puts "tcl_version   : $tcl_version"
   puts "tk_version    : $tk_version"
   puts "patchlevel    : [info patchlevel]"
   puts "platform information:"
   parray tcl_platform

   set fv [file volumes]
   puts "file volumes  : $fv"
   foreach drive $fv  { puts "$drive : [file system $drive]" }

   puts "Now compare ending the program via close-button and File/Exit,"
   puts "and look for wish85.exe in the taskmanager."

 #.

GJS I believe this is the intended operation. This allows a person to close the console and still use the application. Another option would be to simply type "exit" in the console when you are ready to terminate wish, or use tclsh if the application does not need a gui.

Duoas A good question is, "Why are you using the Tk shell for a console program?" But, to answer your question, you need to use the consoleinterp procedure

  console eval {wm protocol . WM_DELETE_WINDOW {consoleinterp eval exit} }

Now you can withdraw . and when the user closes the console window then the main interpreter's exit function is called. When stuck with problems, it is always useful to start perusing the docs. ;-)