I want to implement function for line duplicate(CTRL+D). There is a default binding already in text widget
As per documentation https://www.tcl.tk/man/tcl8.4/TkCmd/entry.html it says:
Control-d deletes the character to the right of the insertion cursor.
No matter what to do it still performs besides my function. How to disable it?
import tkinter as tk
class MyApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.text = tk.Text(self)
self.text.pack(side="top", fill="both", expand=True)
self.text.bind("<Control-d>", self.duplicate_line)
self.text.bind("<Control-D>", self.duplicate_line)
def duplicate_line(self, event=None):
line = self.text.get("current linestart", "current lineend+1c")
self.text.insert("insert lineend+1c", line)
app = MyApp()
app.mainloop()
Thanks
With unbind at the start didn't work.
self.text.unbind("<Control-d>")
self.text.unbind("<Control-D>")