![]() | ![]() | ![]() | ![]() |
Tcl8.5.6/Tk8.5.6 Documentation > TkCmd > clipboardTcl/Tk Applications | Tcl Commands | Tk Commands | Tcl Library | Tk LibraryNAMEclipboard - Manipulate Tk clipboardSYNOPSISclipboard option ?arg arg ...?DESCRIPTIONThis command provides a Tcl interface to the Tk clipboard, which stores data for later retrieval using the selection mechanism (via the -selection CLIPBOARD option). In order to copy data into the clipboard, clipboard clear must be called, followed by a sequence of one or more calls to clipboard append. To ensure that the clipboard is updated atomically, all appends should be completed before returning to the event loop.The first argument to clipboard determines the format of the rest of the arguments and the behavior of the command. The following forms are currently supported:
EXAMPLESGet the current contents of the clipboard.if {[catch {clipboard get} contents]} {
# There were no clipboard contents at all
}
Set the clipboard to contain a fixed string. clipboard clear clipboard append "some fixed string" You can put custom data into the clipboard by using a custom -type option. This is not necessarily portable, but can be very useful. The method of passing Tcl scripts this way is effective, but should be mixed with safe interpreters in production code. # This is a very simple canvas serializer;
# it produces a script that recreates the item(s) when executed
proc getItemConfig {canvas tag} {
set script {}
foreach item [$canvas find withtag $tag] {
append script {$canvas create } [$canvas type $item]
append script { } [$canvas coords $item] { }
foreach config [$canvas itemconf $item] {
lassign $config name - - - value
append script [list $name $value] { }
}
append script \n
}
return [string trim $script]
}
# Set up a binding on a canvas to cut and paste an item
set c [canvas .c]
pack $c
$c create text 150 30 -text "cut and paste me"
bind $c <<Cut>> {
clipboard clear
clipboard append -type TkCanvasItem \
[getItemConfig %W current]
# Delete because this is cut, not copy.
%W delete current
}
bind $c <<Paste>> {
catch {
set canvas %W
eval [clipboard get -type TkCanvasItem]
}
}
SEE ALSOinterp, selectionKEYWORDSclear, format, clipboard, append, selection, typeCopyright © 1995-1997 Roger E. Critchlow Jr.
Copyright © 1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.
|