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
78              Note that on  modern  X11  systems,  the  most  useful  type  to
79              retrieve  for  transferred  strings  is  not  STRING, but rather
80              UTF8_STRING.
81

EXAMPLES

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

SEE ALSO

132       interp(n), selection(n)
133
134

KEYWORDS

136       clear, format, clipboard, append, selection, type
137
138
139
140Tk                                    8.4                         clipboard(n)
Impressum