[Tutor] Help (Antonio Zagheni)
Peter Otten
__peter__ at web.de
Mon Jun 24 17:34:16 CEST 2013
Antonio Zagheni wrote:
>> I am a begginer in Pythonu
>> I did a function that returns a string and I want to copy this to the
>> clipboard. I have tried a lot of suggestions found at Google but nothing
>> works properly. Is there an easy way to do that?
>> I am using Python 2.7 and Windows 7.
>
> It's simple to access the clipboard with Tkinter:
[eryksun]
> >>> from Tkinter import Tk, TclError
> >>> root = Tk()
> >>> root.withdraw()
> ''
> >>> root.clipboard_clear()
>
> >>> root.clipboard_append('eggs ')
> >>> root.clipboard_append('and spam')
> >>> root.clipboard_get()
> 'eggs and spam'
>
> >>> root.clipboard_clear()
> >>> try: root.clipboard_get()
> ... except TclError as e: print e
> ...
> CLIPBOARD selection doesn't exist or form "STRING" not defined
[Antonio]
> But I am trying to paste the clipboard content to MS word and when I do it
> MS word becomes not responding.
>
> So, if you can help...
Please show us the python script you are running and tell us how exactly you
are invoking it.
More information about the Tutor
mailing list