Entry
How do you read from / write to the system clipboard from Tkinter?
Jul 11th, 2000 22:34
unknown unknown, richard_chamberlain
I presume that you want to paste or copy into or out of an entry or
text, these widgets already have copy and paste keystrokes assigned to
them (at least they do on windows). So I can do Control-c and that
copies it into the clipboard and Control-p pastes it. so:
from Tkinter import *
root=Tk()
text=Text(root)
text.pack()
root.clipboard_clear()
root.clipboard_append('python rules!')
def paste(event):
text.event_generate('<Control-v>')
text.bind('<FocusIn>',paste)
root.mainloop()
In this example we append your 'python rules!' to the clipboard and then
wait until the text control gets the focus and then we generate a
<Control-v> event to paste the contents in.