cut & paste text between tkinter widgets

William Gill noreply at gcgroup.net
Wed Aug 3 17:31:26 EDT 2005



>> Is there a simple way to cut and paste from a tkinter text widget to 
>> an entry widget?  I know I could create a mouse button event that 
>> triggers a popup (message widget) prompting for cut/paste in each of 
>> the widgets using a temp variable to hold the text, but I don't wnat 
>> to reinvent the wheel if there already is something that does the job.
> 
> 
> 1) TKinter text and entry widgets should already have proper event 
> bindings for cut/copy/paste.  Test first with your system-default 
> keyboard shortcuts (^C, ^X, ^V on Windows).  I haven't tried it myself, 
> but I think those events bind to '<<Cut>>', '<<Copy>>', and '<<Paste>>', 
> so generating them should Do The Right Thing with selected text.

^C, ^X, and ^V  work just fine!  (I swear I tried that before I posted 
and they didn't???)


> 2) If you need to do any processing on the clipboard data, look at 
> widget.selection_get [so named because of the way that X handles its 
> clipboard]

 From my reading, w.selection_get will return the selected text in w, 
and  places it on the clipboard.   I didn't see any way to get data from 
the clipboard.

Thanks,

Bill




More information about the Python-list mailing list