Version 9 of A minimal Tk program

Updated 2004-03-06 07:22:00

Richard Suchenwirth 2004-03-05 - I think there is no smaller useful Tcl/Tk program possible than this:

 pack [text .t]

As it's just three words long, we might discuss them one by one:

  • text creates a text widget, with all its bindings and features
  • .t is the name I give to this widget (I like minimal things, and the initial of the widget class is short and clear)
  • pack calls a geometry manager to make the widget appear on screen

And how is this useful? Well, just today I had to paste a string from a cmd window into a buffer, edit the backslashes to slashes (and remove linefeeds), and then paste it back into a Cygwin window. Most easily done with a text scratchpad just like this... Another use case: Copying pre-formatted text directly from the MS Internet Explorer into an editor may make it lose its line breaks. Copy it into this window first, then mark it again, and copy on - line breaks have been preserved now.

You could start more instances of this "program", and use them to organize your thoughts, by copying between them.

Modern usage requires that scripts all start in a tclsh, and announce what they need (Tk in this case). This makes the program double as long:

 package require Tk
 pack [text .t]

Another refinement allows to resize the window with the mouse:

 package require Tk
 pack [text .t] -fill both -expand 1

And for real usability (including loading and saving files), you might check A minimal editor...


Well, OK, but there are better ways to handle your example problem.

1 - What stopped your from using Cygwin's own command line as "scratch pad"? Paste, edit path and [Enter]. ???!! Even easier if you use rxvt.

2 - Instead of pasting the path, type cygpath /paste/your/path

3 - I am lazy too, so I have a keyboard shortcut that does that exact same path editing, right in the clipboard, with PowerPro. It's faster.

4 - For this and many other clipboard editing operations, you can use Perl: read the clipboard, parse and edit, write back to clipboard. Unfortunately, Tcl/Tk still can't do that kind of "clipboard-stream-editing" [L1 ]. :-(

Shame on you for using Internet Explorer. :-P


RS replies to anon.: As our product is to run on Win XP, I have that on my desktop too (and Reflection to connect to Solaris and Linux boxes) - and IE is prescribed corporate standard. When I paste a line-wrapped command from cmd.exe to Cygwin, hard newlines are inserted, leading to unwanted early (and bad) execution. I am not aware of cygpath, and wouldn't want to make up a file for this transient operation. And finally, Tcl/Tk can of course access the clipboard, at least for text content.

But you're missing my point a bit: I wanted to demonstrate one of the smallest useful Tk programs possible, and useful it is - at least for me. The Cygwin case just happened to me yesterday, that's why I mentioned it.

LES: I don't miss your point. But sometimes we write things that may cause an urge to reply with only more or less related ideas. The problem is that the wiki is not the proper place for drifting chat like usenet or mailing lists. Perhaps we should just delete everything below "minimal editor"...

But clipboard cannot handle what I mentioned. Read the thread on that link and you'll see.


Arts and crafts of Tcl-Tk programming