clipboard
richard_chamberlain
richard_chamberlain at ntlworld.com
Tue Jul 11 19:06:53 EDT 2000
Hi Keith,
ignore me I misread your question (my wife and I have just had a baby and I
was rather tired).
I presume that you want to paste or copy into or out of a 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.
Richard
Keith Murphy <kpmurphy at my-deja.com> wrote in message
news:8kfbd7$kpc$1 at nnrp1.deja.com...
> hi richard,
>
> i tried that, and i got the following error message...
>
> Exception in Tkinter callback
> Traceback (innermost last):
> File "/usr/local/lib/python1.5/lib-tk/Tkinter.py", line 764, in
> __call__
> return apply(self.func, args)
> File "tkPad.py", line 146, in paste
> contents = root.selection_get()
> File "/usr/local/lib/python1.5/lib-tk/Tkinter.py", line 280, in
> selection_get
> return self.tk.call(('selection', 'get') + self._options(kw))
> TclError: PRIMARY selection doesn't exist or form "STRING" not defined
>
>
> ?? thanks,
>
> -->keith
>
> In article <Y8sa5.10253$_O.174557 at news2-win.server.ntlworld.com>,
> "richard_chamberlain" <richard_chamberlain at ntlworld.com> wrote:
> > Hi Keith,
> >
> > content=root.selection_get()
> >
> > Richard
> >
> > Keith Murphy <kpmurphy at my-deja.com> wrote in message
> > news:8kdeae$9fv$1 at nnrp1.deja.com...
> > > In article <8kddiq$8oc$1 at nnrp1.deja.com>,
> > > Keith Murphy <kpmurphy at my-deja.com> wrote:
> > > > how do you read from / write to the system clipboard from Tkinter?
> > > i'm
> > > > on a unix machine, if that matters. Thanks,
> > > >
> > > > -->keith
> > > >
> > > > Sent via Deja.com http://www.deja.com/
> > > > Before you buy.
> > > >
> > >
> > > i've found out that...
> > >
> > > >>> root.clipboard_clear()
> > > >>> root.clipboard_append('python rules!')
> > >
> > >
> > > ... places text on the system clipboard, but how do you paste?
> > > thanks...
> > >
> > > -->keith
> > >
> > >
> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.
> >
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
More information about the Python-list
mailing list