Reputation: 13
I want to enable copying of the text placed on canvas. Is it possible to do so? I have placed text using:
.c.canvasName create text 100 90 $var -font {Courier -12} ...
where var contains a tcl tk matrix.
Upvotes: 1
Views: 486
Reputation: 13272
As Donal wrote, ctext.tcl
gives many helpful hints on how to manage text items in canvases.
Note that it doesn't demonstrate copying text to the clipboard. Use the following code for a rudimentary clipboard copy function:
$c bind text <<Copy>> "textCopy $c"
...
proc textCopy {w} {
clipboard clear
clipboard append [selection get]
selection clear
}
clipboard clear
empties the Tk clipboard, and clipboard append
copies new text to it. On Windows you can then paste this text using the normal Ctrl+V.
selection get
copies text from the current selection and throws an error if no text is selected. Use
catch {clipboard append [selection get]}
to suppress such errors.
selection clear
unselects the selection.
Upvotes: 1