Tcl/Tk Cookbook - Text Editor


Purpose

This chapter introduces the Tk text widget. Tk text widget has the ability to include the following forms of annotation:

The third form of annotation is not covered in this chapter.

Apart from the text widget, scrollbar, menubar, pulldown menu and popup dialog box are also introduced.

You will need

At this point it is assumed that the reader has read through the previous chapters and has familiarity with Tcl and Tk basics, especially if (s)he is new to Tcl and Tk.

Dish to Serve Up

Create a simple text editor. Include the ability to tag all occurances of a given string.

Recipe

It is advisable to develop this application three separate script files. All the code is under ~cookbook/code/ch3 with names editor.tcl, popup.tcl and message.tcl. The file filesel.tcl contains the contributed script for a fileselectionbox. Copy this filesel.tcl into your current working directory. For convenience, we will assume that the three script files you will be generating are named ed.tcl, pop.tcl and mes.tcl.

  1. Create a scrollable text widget
  2. Add menubar, menus and register callbacks
  3. Create pop up dialogue boxes
  4. Create callbacks
  5. Add Tags to text strings

Acknowledgement

A slightly modified version of Mario Jorge Silva's fileselectionbox is used.