In addition to @JacksonPro 's answer, you could also try this approach,
from tkinter import *
def backspace(event):
if text.tag_ranges(SEL):
text.insert(SEL_FIRST,text.get(SEL_FIRST, SEL_LAST))
else:
last_char=text.get('1.0','end-1c')[-1]
text.insert(END,last_char)
root=Tk()
text=Text(root)
text.pack()
text.bind('<KeyRelease>', lambda event=None:root.clipboard_clear())
text.bind('<KeyPress>', lambda event=None:root.clipboard_clear())
text.bind('<BackSpace>', backspace)
root.mainloop()
This basically will clear your clipboard everytime you perform a KeyPress
or a KeyRelease
and hence copying/pasting will not be possible. The backspace()
function obtains the last character and re-inserts it at the last position wherever backspace is used and indirectly restrics it's function. My previous appreach to backspace()
wasn't right since it didn't take selection into account, but now it should work in all the cases, if there is something selected, it will obtain the selected text and insert it at the beginning of the selection (SEL_FIRST
) else it will just obtain and reinsert the last charecter.