1clipboard(n)                 Tk Built-In Commands                 clipboard(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       clipboard - Manipulate Tk clipboard
9

SYNOPSIS

11       clipboard option ?arg arg ...?
12_________________________________________________________________
13
14

DESCRIPTION

16       This command provides a Tcl interface to the Tk clipboard, which stores
17       data for later retrieval using the selection mechanism (via the -selec‐
18       tion  CLIPBOARD  option).   In  order  to copy data into the clipboard,
19       clipboard clear must be called, followed by a sequence of one  or  more
20       calls  to  clipboard  append.   To ensure that the clipboard is updated
21       atomically, all appends should be completed  before  returning  to  the
22       event loop.
23
24       The  first  argument  to clipboard determines the format of the rest of
25       the arguments and the behavior of the command.  The following forms are
26       currently supported:
27
28       clipboard clear ?-displayof window?
29              Claims  ownership  of  the  clipboard  on  window's  display and
30              removes any previous contents.  Window defaults to “.”.  Returns
31              an empty string.
32
33       clipboard append ?-displayof window? ?-format format? ?-type type? ?--?
34       data
35              Appends data to the clipboard on window's display  in  the  form
36              given by type with the representation given by format and claims
37              ownership of the clipboard on window's display.
38
39              Type specifies the form in which the selection is to be returned
40              (the desired “target” for conversion, in ICCCM terminology), and
41              should be an atom name such as  STRING  or  FILE_NAME;  see  the
42              Inter-Client   Communication  Conventions  Manual  for  complete
43              details.  Type defaults to STRING.
44
45              The format argument specifies the representation that should  be
46              used to transmit the selection to the requester (the second col‐
47              umn of Table 2 of the ICCCM), and defaults to STRING.  If format
48              is  STRING,  the selection is transmitted as 8-bit ASCII charac‐
49              ters.  If format is ATOM, then the data is divided  into  fields
50              separated  by  white  space; each field is converted to its atom
51              value, and the 32-bit atom value is transmitted instead  of  the
52              atom  name.   For any other format,  data is divided into fields
53              separated by white space and each field is converted to a 32-bit
54              integer;  an  array  of integers is transmitted to the selection
55              requester.  Note that strings passed  to  clipboard  append  are
56              concatenated  before conversion, so the caller must take care to
57              ensure appropriate spacing across string boundaries.  All  items
58              appended  to the clipboard with the same type must have the same
59              format.
60
61              The format argument is needed only for compatibility with  clip‐
62              board requesters that do not use Tk.  If the Tk toolkit is being
63              used to retrieve the CLIPBOARD selection then the value is  con‐
64              verted  back  to  a  string  at the requesting end, so format is
65              irrelevant.
66
67              A -- argument may be specified to mark the end of options:   the
68              next  argument will always be used as data.  This feature may be
69              convenient if, for example, data starts with a -.
70
71       clipboard get ?-displayof window? ?-type type?
72              Retrieve data from the clipboard on  window's  display.   Window
73              defaults  to  “.”.  Type specifies the form in which the data is
74              to be returned and should be an atom  name  such  as  STRING  or
75              FILE_NAME.  Type defaults to STRING.  This command is equivalent
76              to “selection get -selection CLIPBOARD”.
77

EXAMPLES

79       Get the current contents of the clipboard.
80              if {[catch {clipboard get} contents]} {
81                  # There were no clipboard contents at all
82              }
83
84       Set the clipboard to contain a fixed string.
85              clipboard clear
86              clipboard append "some fixed string"
87
88       You can put custom data into the clipboard  by  using  a  custom  -type
89       option.  This  is not necessarily portable, but can be very useful. The
90       method of passing Tcl scripts this way  is  effective,  but  should  be
91       mixed with safe interpreters in production code.
92              # This is a very simple canvas serializer;
93              # it produces a script that recreates the item(s) when executed
94              proc getItemConfig {canvas tag} {
95                 set script {}
96                 foreach item [$canvas find withtag $tag] {
97                    append script {$canvas create } [$canvas type $item]
98                    append script { } [$canvas coords $item] { }
99                    foreach config [$canvas itemconf $item] {
100                       lassign $config name - - - value
101                       append script [list $name $value] { }
102                    }
103                    append script \n
104                 }
105                 return [string trim $script]
106              }
107
108              # Set up a binding on a canvas to cut and paste an item
109              set c [canvas .c]
110              pack $c
111              $c create text 150 30 -text "cut and paste me"
112              bind $c <<Cut>> {
113                 clipboard clear
114                 clipboard append -type TkCanvasItem \
115                       [getItemConfig %W current]
116                 # Delete because this is cut, not copy.
117                 %W delete current
118              }
119              bind $c <<Paste>> {
120                 catch {
121                    set canvas %W
122                    eval [clipboard get -type TkCanvasItem]
123                 }
124              }
125
126

SEE ALSO

128       interp(n), selection(n)
129
130

KEYWORDS

132       clear, format, clipboard, append, selection, type
133
134
135
136Tk                                    8.4                         clipboard(n)
Impressum