Elimina i contenuti della casella di testo Tkinter

Tkinter Il widget di testo ha il metodo delete(first, last=None)
per eliminare i caratteri all’indice di first
, o all’interno dell’intervallo di (first, last)
dalla casella di testo.
Se last
non viene fornito, viene cancellato solo il carattere specificato nella posizione first
.
Codice di esempio per cancellare il contenuto del widget di testo Tkinter
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"
si riferiscono al primo carattere e all’ultimo carattere dei contenuti nel widget Text
, lo stesso introdotto nell’articolo di come ottenere l’input del 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.
LinkedInArticolo correlato - Tkinter Text
- Come rendere Tkinter Text widget di sola lettura
- Ottieni l'input dalla casella di testo Tkinter
- Imposta il carattere del widget di testo Tkinter
- Imposta il testo del widget di testo Tkinter con un pulsante