Hi,

How do I disable Copy/Cut/Paste operations on a textbox in Tkinter.

I want to implement this in simple login form, where I found I can copy or paste or cut from textbox which is meant to accept PASSWORD.

Can we do that? How?


Thank you,
Regards,
kath.

This is a partial solution, but I want to try to figure it out, 'cause it's a cool problem.

If you use an Entry() widget for the password and then set

show='*'

in the Entry widget, the Control-c will only copy the ******s rather than the underlying characters. That would give an attacker nothing except the password length (which would of course be 10+ chars, right :))

from Tkinter import *

mainw=Tk()
mainw.e = Entry(mainw,show='*')
mainw.e.grid()
mainw.mainloop()

with the result of

*********

when the password is copy-and-pasted into IDLE.

Hope it helps,
Jeff

I think that you need to bind events that select text, like when you select text with mouse or shift+arrows. make event funct that will enable cut/copy/paste enabled and disabled when you unselect text, bind to that funct mousc click and shift+arrows.

I hope you understand what I mean, sorry for bad english

Glad people chose to reply, but none of those are good answers. I HATE java solutions that involve breaking cross-platform compatibility. Obviously some low-level programs require operating system specific solutions, and you need to carefully consider that before tackling a project (And use something else if so). Solutions such as intercepting specific key sequences aren't even single-platform compatible, because I could easily map my copy function to different keys and subvert the whole thing.

This, however, is not one of those cases. You can solve this problem with one line of code: txtMyTextbox.setTransferHandler(null); This will disable copy/cut/paste. TransferHandler is a carry-all object maintained by the root JComponent class of most swing components. Its job is to differentiate between different types of data and carry that data during a copy/paste action.

If you want to get cute, you could even override certain functions and make it copy "GO AWAY" or something less friendly whenever they tried. Also, if your main interest is program security, you really need to use a different language or compile your java to native code. Disassembling java class files is easy and your program can be easily altered. Java supports good information security, but your program itself is vulnerable.

If you want to disable copy/paste set your text widget, for instance text1, to ...

text1['state'] = 'disabled'

This also disables insert so you have to temporarily change it with ...

text1['state'] = 'normal'

Wow, teach my ass to double check where I'm posting. I was reading another thread and accidentally replied here.

But if you ever are trying to do this in Java, there ya go! lol

Glad people chose to reply, but none of those are good answers. I HATE java solutions that involve breaking cross-platform compatibility. Obviously some low-level programs require operating system specific solutions, and you need to carefully consider that before tackling a project (And use something else if so). Solutions such as intercepting specific key sequences aren't even single-platform compatible, because I could easily map my copy function to different keys and subvert the whole thing.

This, however, is not one of those cases. You can solve this problem with one line of code: txtMyTextbox.setTransferHandler(null); This will disable copy/cut/paste. TransferHandler is a carry-all object maintained by the root JComponent class of most swing components. Its job is to differentiate between different types of data and carry that data during a copy/paste action.

If you want to get cute, you could even override certain functions and make it copy "GO AWAY" or something less friendly whenever they tried. Also, if your main interest is program security, you really need to use a different language or compile your java to native code. Disassembling java class files is easy and your program can be easily altered. Java supports good information security, but your program itself is vulnerable.

Hi,

How do I disable Copy/Cut/Paste operations on a textbox in Tkinter.

I want to implement this in simple login form, where I found I can copy or paste or cut from textbox which is meant to accept PASSWORD.

Can we do that? How?


Thank you,
Regards,
kath.

You need to unbind action copy and paste:

text=Text()
text.unbind("<<paste>>")  
text.unbind("<<copy>>")
Comments
nice contribution

Please don't revive 6 years old threads. Also this thread is about python's tkinter. It is not at all related te asp.net or jquery.

This question has already been answered. Start a new discussion instead.