cut & paste text between tkinter widgets

Repton jfouhy at paradise.net.nz
Thu Aug 4 19:36:23 EDT 2005


Christopher Subich wrote:
> In experimenting with this, I found a slight... fun issue involved in
> this.  Selection_get is the correct method to call, but it doesn't quite
> work out of the box.
>  >>> g.selection_get()
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File "C:\Python24\Lib\lib-tk\Tkinter.py", line 574, in selection_get
>      return self.tk.call(('selection', 'get') + self._options(kw))
> _tkinter.TclError: PRIMARY selection doesn't exist or form "STRING" not
> defined
>
> This poses a small problem.  I'm not sure whether this is a
> Win32-related issue, or it's because the PRIMARY selection isn't fully
> configured.

You need to select something first :-)

>>> from Tkinter import *
>>> tk = Tk(); e = Entry(tk); e.pack()
>>> # Type 'foo' into the Entry, then highlight it
...
>>> e.selection_get()
'foo'

e.selection_get() will raise TclError if the widget you call it on has
nothing selected.

>  >>> g.selection_get(selection='CLIPBOARD')

I didn't know about this, though..

-- 
John.




More information about the Python-list mailing list