15.3 Text Clipboard Functions
Both the Text widget and the TextField widget have convenience routines that support communication with the
clipboard. Using these functions, you can implement the standard cut, copy, and paste functionality, as well as support
communication with other windows or applications on the desktop. If you are not familiar with the clipboard and how
it works, see Chapter 17, The Clipboard. Briefly, the clipboard is one of three transient locations where arbitrary data
such as text can be stored so that other windows or applications can copy the data. For the Text widget, we are only
interested in copying textual data and providing visual feedback within the widget. The Text widget can send and
receive data from all three of the locations, depending on the interface style that you are using.
As described earlier in this chapter, the user typically selects text by pressing the first mouse button and dragging the
pointer across the text. When text is selected, it is rendered in reverse video and automatically copied into the primary
selection. Now the user can paste text from the primary selection into any Text widget on the desktop by pressing the
middle mouse button. The insertion cursor is moved to the location of the button press, and the data is automatically
copied into the Text widget at this position. This functionality works by default within the Text widget. However, the
actions operate on the primary selection, not the clipboard selection. Furthermore, the actions ...