Updated 2001-06-25 09:53:02

Here are a few little gems that you might be able to use with Tk widgets. Other goodies can be had at Tk Examples or Bag of Tk Algorithms.

Note that most of these little tricks are documented in the man pages. Read them carefully, and you'll find all kinds of wonderful little things you can do.

Check out Tcl Gems for some other good ideas.

Inserting in a text widget

You can programmatically insert text into a text widget using the insert subcommand. You have to specify where you want to insert the text with an index, which can be one of several forms. You can specify the line number and character position with using the "line.char" format or the special index name end. You can also do a little math using the incices, like "end - 2 lines"

You can also use marks to specify locations in the text. You can add your own marks, or use one of the special marks. The mark insert indicates the current cursor position, and the mark current indicates the current mouse pointer position. So this command will insert new text at the current cursor position:
  .t insert "current" $newText

Arts and Crafts of Tcl-Tk Programming - Useful Tk Widgets