Tkinter Text Widget ใช้เพื่อเพิ่มตัวเขียนข้อความในแอปพลิเคชัน มีคุณลักษณะและคุณสมบัติมากมายที่ใช้ในการขยายการทำงานของโปรแกรมแก้ไขข้อความ ในการลบเนื้อหาที่ป้อน เราสามารถใช้ delete("start", "end") วิธีการ
ตัวอย่าง
#Import the tkinter library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
#Set the geometry
win.geometry("600x250")
#Define a function to clear the input text
def clearToTextInput():
my_text.delete("1.0","end")
#Create a text widget
my_text=Text(win, height=10)
my_text.pack()
#Create a Button
btn=Button(win,height=1,width=10, text="Clear",command=clearToTextInput)
btn.pack()
#Display the window without pressing key
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะสร้างวิดเจ็ตข้อความและปุ่มที่สามารถใช้ล้างข้อความที่ป้อนได้

ตอนนี้คลิกที่ปุ่ม "ล้าง" มันจะล้างข้อความที่ป้อน