2
votes

I'm using Tkinter to make a small program, but I've run into troubles with pasting.

I want to be able to click text in a Text widget with the middle mouse button without it pasting anything. I have tried things like binding over it:

text.bind('<<Paste>>', lambda x: 'break')

But this only disables the keyboard Ctrl-V pasting, not the middle mouse. This makes me think that perhaps it is an X11 (I am on Debian) issue, but even if that is the case, is there a way to intercept the paste event? I would like to make it as portable as possible.

1
Look inside text.tcl which is usually in /usr/share/tcltk8.6 on debian to see what bindings the text widget has by default. This will tell you what you need to re-bind. - msw
Thank you! It looks like what I needed to bind over was <<PasteSelection>>, instead of <<Paste>>. This preserves the Ctrl-V pasting, but disables the middle click paste. You can post it as an answer and I'll be happy to accept :) - user4934382

1 Answers

0
votes

The default bindings for the text widget are in a file called text.tcl which usually lives in /usr/share/tcltk8.6 on Debian.

By examining the default bindings you can find which you want to override or unbind. As you mentioned in your comment you found that it was the <<PasteSelection>> rather than the <<Paste>> binding that was doing what you didn't want.