Microsoft Windows and Tk

Purpose: Provide a collection of hints for making Tk more convenient on Microsoft Windows.

  • If you write to stdout or stderr, and haven't redirected your standard channels, you are writing into the Windows Wish Console whether you know it or not! Once you get more than a few hundred lines of output into it, the Wish console gets very slow; visit the page referenced above to see how to take care of it.
  • The care and feeding of the system menu is discussed in menu.
  • Windows Wish Console has some tricks for dealing with the Tk console on the Windows platform. The menu page shows how to add a Show Console item to the system menu.
  • (KBK 8 January 2001) The Wish console can also be used from within C++ code; Cplusplus streams and Tcl channels shows how.
  • Printing a canvas under Windows shows one way to get printout from the canvas on Windows.
  • There are various hints on running DDE, on a page called, predictably enough, dde.
  • Example of using the registry package can be found at Windows Registry Browser
  • Invoking browsers shows how to launch a Web browser under control of a Tcl script.
  • Text widget contents, even with exotic Unicodes, can be printed on WinNT by copying and pasting into a Notepad, provided you have a Unicode font like Bitstream Cyberbit (recent Microsoft fonts also support Greek, Russian, Arabic, Hebrew), and have set Notepad to use that. The "higher" editors like Wordpad and Word don't accept exotic text pasting so easy, since they refer to an explicit font setup that also includes the language. RS
  • If a Tk app pops up a fileselector dialog at its beginning, the main window may not react to clicks or keys even if it seems to be in focus. A (on Unix redundant) update before the fileselector command fixed that. - RS
  • Tk can fake the little thingy with three diagonal lines that lives at the lower right corner and lets you resize a window. Resize control shows how.
  • A different implementation for a windows like sizer control.
  • This Windows Application Framework automates some of the repetitive tasks for making an application with a Windows feel.

What if you want "to go the other way", and, for example, "Give Unix a Windows look and feel"? There's a Wiki page for that, too.


Interesting note - recently someone on comp.lang.tcl reported that a Hewlett Packard Pavillion, running Windows XP, came with Tcl installed. Another user reports that MKS Software's (former Mortice Kern Systems) MKS Toolkit - a package of Unix-like utilities for Windows, comes with Tcl/Tk (along with Perl, awk, etc.). Jeff Hobbes mentioned that Microsoft's Interix toolkit comes with Tcl along with 'a ton' of other "unix" utilities. And of course Cygnus comes with a version of Tcl/Tk (and there are users which provide newer versions of Tcl/Tk/other extensions for Cygnus).


Sarnold 2006-04-25: There is a bug in Tk 8.4.12 with Windows ME. When you close the application window, a wish process still is in background (no window attached to it, but you can see it if you press Ctrl-Alt-Delete). So the following line is needed to avoid this behaviour:

 bind . <Destroy> {exit}

The minimal script needing this trick follows here:

 while 1 {catch {update}}

MG Is this actually a bug? This happens in XP too with the code above, but only when there's an infinite loop running. If you have a loop like

  set i 150000
  while {$i} {incr i -1 ; catch {update}}

then the process exits when the loop reaches its end. This seems more like a useful feature than a bug, to me, giving you the chance to finish something important you could be doing in a loop when a user closes the app, but still (with the bind) giving the opportunity to break out of the loop if you prefer...


See also


Exceed on Windows documents some issues using Tk with Exceed on Windows.