Getting A _tkinter.TclError When I Try To Cut And Paste In A Custom Tkinter Text Field
Solution 1:
_tkinter.TclError: text doesn't contain any characters tagged with "sel"
I don't think I have a proper fix, but I have something that prevents your code from crashing.
Replace this:
result = self.tk.call(cmd)
... with this:
try:
result = self.tk.call(cmd)
except Exception:
return None
It may mask other things that should legitimately throw an error, but at the moment it's the best solution I have.
When I try to paste the text via the keyboard shortcut, it doesn't give me an error, it just pastes my text twice on the same line.
It's probably doing it twice because tkinter already has a default binding for cut and paste. What's probably happening is that your binding is firing and then the built-in binding is firing. If you want to prevent the built-in binding from taking effect you need to return "break"
from paste
. I'm only guessing at this point since you didn't provide a [mcve] for that.
Post a Comment for "Getting A _tkinter.TclError When I Try To Cut And Paste In A Custom Tkinter Text Field"