Getting the XP clipboard in tkinter

Edward K. Ream edream at tds.net
Sun Jun 30 10:49:38 EDT 2002


Hi,

If a clipboard_get() convenience method existed in tkinter, what would
it look like?

I would like to do something that seems trivial using Tkinter:
namely get the contents of the "global" clipboard in Windows XP.  When
the focus in a text widget my app uses virtual Cut, Copy and Paste
events, like this:

w.event_generate(virtual_event_name("Copy"))

This works.  That is, the text copied in this manner can be read by my
app and can be pasted by my app using the similar "Paste" event.

However, there are times when I need to get this same information when
the focus is in a canvas, and I just don't see how to do it.  In such
cases, my app writes to the clipboard using:

app().root.clipboard_clear()
app().root.clipboard_append(s)

where app().root is a top level widget.  Other apps can read what has
been written to the clipboard!  But the obvious code to read the
clipboard:

s = app().root.selection_get()

takes an exception. I must be missing something really simple.  The
following two statements also take exceptions:

s = app().root.selection_get("clipboard")
s = app().root.selection_get(".")

Please help.  This is driving me crazy.  

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list