Como excluir o conteúdo da caixa de texto Tkinter
O widget Tkinter Text tem o método delete(first, last=None) para excluir os caracteres no índice de first, ou dentro do intervalo de (first, last) da caixa de texto.
Se last não for dado, somente o caractere especificado na posição first será excluído.
Exemplo de código para limpar o conteúdo do Tkinter Text Widget
import tkinter as tk
root = tk.Tk()
root.geometry("400x240")
def clearTextInput():
textExample.delete("1.0", "end")
textExample = tk.Text(root, height=10)
textExample.pack()
btnRead = tk.Button(root, height=1, width=10, text="Clear", command=clearTextInput)
btnRead.pack()
root.mainloop()
textExample.get("1.0", "end")
"1.0" e "end" referem-se ao primeiro caractere e ao último caractere do conteúdo do widget Text, o mesmo que foi introduzido no artigo de como obter a entrada do widget Text.
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn Facebook