How to delete the selected text in a ScrolledText widget in Tkinter?
04:42 29 Jun 2026
from tkinter import scrolledtext, Tk, Button
 
def copy():
    try:
        txt = text.get('sel.first', 'sel.last')
        window.clipboard_append(txt)
    except tk.TclError:
        pass
 
window = Tk()
 
text = scrolledtext.ScrolledText(window)
text.pack()
 
button = Button(window, text="Copy", command=copy)
button.pack()

window.mainloop()

I'm making a Notepad application in Python with the ScrolledText widget from tkinter. I've already made a copy function (see the code above), but I also want a delete function. With that function, you can delete the selected text. I know how you can see which text is selected, but I don't know how to delete text in ScrolledText. How can I do that?

python tkinter tkinter-scrolledtext