cut & paste text between tkinter widgets

Christopher Subich spam.csubich+block at block.subich.spam.com
Wed Aug 3 11:37:31 EDT 2005


William Gill wrote:
> 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.

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]



More information about the Python-list mailing list