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

DESCRIPTION

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

EXAMPLES

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

SEE ALSO

130       interp(n), selection(n)
131

KEYWORDS

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