Getting the XP clipboard in tkinter

Edward K. Ream edream at
Sun Jun 30 16:49:38 CEST 2002


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:


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:


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

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 K. Ream   email:  edream at
Leo: Literate Editor with Outlines

More information about the Python-list mailing list